Hi,
If my declarations are this:
#define TAmt 0.40
int main(void)
{
double MTot=0.0;
....
MTot+=TAmt;
...
}
Let's say I hit this incrementing statement 5 times in the same program, so MTot is 2.00. If I divide MTot by TAmt, I get 5.
cout <<(int)(Mtot/TAmt);
(I want to use a int type-cast to display an integer)
That works fine. Why then, if I hit these statements 6 times and MTot is 2.40 and do this:
cout <<(int)(Mtot/TAmt);
...I get 5!!! It works for various other numbers but most of them will be incorrect. If I remove the (int) type-cast I get the right answer in all cases, but I don't want to display 6.00, I want just 6 to display.
Obvioulsy the type-cast and precision of the double has something to do with it....what is gong on and how can I fix this?
Thanks.
-Tyler
If my declarations are this:
#define TAmt 0.40
int main(void)
{
double MTot=0.0;
....
MTot+=TAmt;
...
}
Let's say I hit this incrementing statement 5 times in the same program, so MTot is 2.00. If I divide MTot by TAmt, I get 5.
cout <<(int)(Mtot/TAmt);
(I want to use a int type-cast to display an integer)
That works fine. Why then, if I hit these statements 6 times and MTot is 2.40 and do this:
cout <<(int)(Mtot/TAmt);
...I get 5!!! It works for various other numbers but most of them will be incorrect. If I remove the (int) type-cast I get the right answer in all cases, but I don't want to display 6.00, I want just 6 to display.
Obvioulsy the type-cast and precision of the double has something to do with it....what is gong on and how can I fix this?
Thanks.
-Tyler