- 1
in C++; I wanted to take a simple discount (part of my program) , i wrote the program, and my formula is correct but output is w
int main() { float d; d =50 - ( 50/100*15); cout << d; } output is 50; it should be 42.5
3 Answers
+ 3
(50.0/100.0*15.0)
+ 5
faizan moriani ,
the reason for your problem is that the numbers in the expression (50 / 100 * 15) are all integer numbers. so 50 / 100 => 0 and 0 * 15 => 0, so finally 50 - 0 => 50.
+ 2
by using only integer literals you get the result as integer (0*15 == 0)