-
Adding big numbers
I have a running total that should show up to one billion, maybe ten.
I've tried adding with int's but ended up with a negative number.
I tried float and double but got a results of 2.85067e+009
How can I see it as a whole number like 285067763463?
-
Code:
#include <iomanip>
...
int main() {
cout.setf(ios::fixed, ios::floatfield);
cout.setf(ios::showpoint);
...
Try adding that to your program.
Anything bigger than your compiler's long double would require you to find a custom datatype that someone made. Try this:
http://www.swox.com/gmp/
-
If the number is only going to be positive, you can use unsigned int instead of int. I think an int will hold +/- 2 billion. An unsigned int is roughly 4 billion. For larger numbers, you might consider "long int" if your processor is 64-bit, or a platform-specific 64 bit integer otherwise. For VC, the 64 bit int is type __int64.
-
The _int64 worked. Problem now is if I try std::cout with this variable then I get "'operator <<' is ambiguous" at compile time.
-
Make sure you've included <iostream>, <iostream.h> gives that error.
Also, use two underscores: __int64.