+ 1
C++ Percentage Error help
void main() { int sub1,sub2,sub3,sub4,sub5,total_percentage; clrscr(); cout<<"enter sonething\n"; total_percentage=(sub1+sub2+sub3+sub4+sub5)/500; cout<<"the total\n"<<total_percentage; getch(); } it is showing 0 always.
2 Réponses
+ 3
(int + int + …) is int.
500 is int.
int / int gives the expected result rounded off.
2/3 = 0
5/3 = 1
25/2 = 12
You must do a static_cast<double>(one_of_your_division_operands)
It converts the argument to a double precision floating point number.
+ 1
thanks sir