Hi! I need urgent help with a code where I frind the product of 10, 100, 1000, and 10000. So the actual answer would be 10,000,000,000 but when i write out my code the product that it gives me is 1.41007E9 which isn't true. I know that I'm supposed to truncate it somehow but im completely lost and i feel like I've tried everything. Can someone please help me!! Thanks :)
1 2 3 4 5 6 7 8 9
#include <iostream>
usingnamespace std;
int main()
{
float x = (10 * 100 * 1000 * 10000);
cout << "the product of 10, 100, 1000, and 10000 is = " << x << " " << endl;
return 0;
}
He could have used int, which is faster.
For a single calculation like this speed is not a concern.
10 * 100 * 1000 * 10000 gives 10000000000 which requires 34 bits to represent as a binary integer. Many implementations use 32-bit integers - indeed that was the cause of the original error and why this question was posted in the first place.