Hello everyone, and thank you in advance for any help you can give!

I am working on a simple program with some long integers, which I have defined as type long long, with LLU after them. I am trying to use these variable names in an arithmetic expression, but when the results print out, the number simply shows as a 0. I have tried putting simple numbers in the expression, which worked, so I was thinking that maybe it has something to do with the fact that I have LLU after my numbers. If that is the case, however, I need a new idea on how to work with this program, because I can't define those integers as anything but long long with LLU after it.

Any ideas on how to work this out?

#include <iostream>

using namespace std;

int main(int, char**) 
{   
    long long n = 6647817899LLU;
    long long f = 10299685494LLU;
    int i = ((f - n) / n) * 100;
    cout << "Part 4: " << f << " is " << i 
         << "% more than " << n << endl;
    
system("pause");
return 0; }
#include <iostream>

using namespace std;

int main(int, char**) 
{   
    long long n = 6647817899LLU;
    long long f = 10299685494LLU;
    int i = ((f - n) / double(n) ) * 100;
    cout << "Part 4: " << f << " is " << i 
         << "% more than " << n << endl;
    
system("pause");
return 0; }

Thank you! If I may ask, why is that the only variable that gets the double in the expression itself?

> why is that the only variable that gets the double in the expression itself?
(f-n) and 100 are automatically converted to double by the compiler. you could also write ( double(f - n) / n ) * 100; or ( double(f - n) / double(n) ) * 100.0 ;

Ah, okay. Thanks for all your help!! :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.