-
Arrrrrggghhh
Code:
#include <iostream.h>
int main()
{
int mass;
cout<<"Enter the mass in kg: ";
cin>>mass;
int C=300000000;
double energy=double(mass*(C*C));
cout<<"This mass would produce "<<energy<<" Joules of energy."<<endl;
cout<<"It could power "<<(energy/360000)<<" 100-watt light bulbs for an hour."<<endl;
return (0);
}
enter mass 0.01
should produce 9e+14
light 2.5e+09 light bulbs
so why the hell do i get 0?
-
why is there a 'double' in front of (mass*......?
-
thats a big number, maybe TOO big for your system? :D
its happened before...if you use a too big of a number it goes to the max which is like 2729398012 or something lol
-
As I recall, and int can only contain values ranging from -32000 to +32000 (or thereabouts). This statement:
int C=300000000;
is assigning a very large number to a small area.
I don't have my book on me, but to point you in the right direction... look up the various data types, and how much data they can hold.
You might looking at long int, or maybe unsigned long int.
-
Did anyone notice the fact that mass is an int?
Integer types truncate any decimal part of the number so
0.01 = 0 as an int.
You might start by using a floating point variable then use an unsigned long int to cover the large numbers.
-
taylorguitarman is god, all bow down... *bows*
lol, i didnt even notice that, i just assumed his number was too big :D but then again, im a big fat hairy jelatenous noob
-
Sorry, not a god; it's just easier to find errors in someone else's code.
-
**searches for a new god**
pop quiz:: how many bytes in 64 bits?
-
512
but and the regular int (32 bit) range is -2,147,483,648 to 2,147, 483, 647 .
-
sorry, I mis-read your post Paro, The correct answere is 8 not 512. 512 is the number of bits in 64 bytes 8 is the number of bytes in 64 bits.
-
8 but...
I think you meant how many bits in 64 bytes.
-
no i meant what i said and i fooled you all!!!
NOW WHO IS GOD!!! :D jk :rolleyes:
-
If its not 512 and its not 8 what is it?
-
it is 8, i didnt say it wasnt either of them...i think its 8 anyway...
god i need a new god
**continues search for a god**
-
howbout me.....oh me me me try me
can i be your god?
anyway, with any variable type why am I always getting 0?