working with decimals
Not really sure if this is a maths question or not.
Anyway, I am building a small calculator, and am trying to implement some decimals. The following code is called if the decimal bool is true (which it is if the decimal key has been pressed) and a number has been entered.
int c = 10; //only 1 decimal place, so we use 10, if were 2
//we would use 100, 3 use 1000, etc
double temp;
temp = a / c; //a is the int number entered by the user
DisplayedNumberA = DisplayedNumberA + temp;
//DisplayedNumberA is a double which holds our display figure
Now, as far as I can see, if (double) DisplayedNumber was previously 12 and a = 5, DisplayedNumberA should now be 12.5 .
But for some reason my program isn''t telling me this answer. Infact, DisplayedAnswer isn''t changing at all. I just wanted to check with you guys, that this portion of code is correct.
I bet this problem occurs because you divide DOUBLE number on INTEGER! try changing either:
or
in your code.
Hope this helps
|
or
|
in your code.
Hope this helps
![](wink.gif)
C++ RULEZ!!! :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement