Friday, July 31, 2009

Percent in c++?

Hi, I want to calculate percent of 100 in C++.





For example, I'm making a progress bar, how would I make it so


number = 5


total = 10


percent = 50

Percent in c++?
int pct=(number*100)/total;





You could also cast to a double to get a floating point percentage. If you are only interested in whole numbers that is not necessary.
Reply:take percent as double data type;





int x, t;


double p;


scanf("%d%d",%26amp;x,%26amp;t);


p=(x*100)/t;


printf("%f", p);


No comments:

Post a Comment