working with decimals

Started by
1 comment, last by leggyguy 22 years, 2 months ago
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.
Advertisement
I bet this problem occurs because you divide DOUBLE number on INTEGER! try changing either:

  double c = 10.0;  


or

  temp = a / double(c);  


in your code.

Hope this helps
C++ RULEZ!!! :)
you''re right, I really should have checked that, I thought it would be something that wasn''t my fault.

Silly me.

This topic is closed to new replies.

Advertisement