Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

  1. Home >
  2. All Categories >
  3. Computers & Internet >
  4. Programming & Design >
  5. Resolved Question
BAK BAK
Member since:
December 23, 2006
Total points:
872 (Level 2)

Resolved Question

Show me another »

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
David B by David B
Member since:
December 10, 2007
Total points:
3,476 (Level 4)

Best Answer - Chosen by Asker

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.
  • 3 people rated this as good
Asker's Rating:
5 out of 5
Asker's Comment:
Thanks. Exactly as I needed, works perfect. :D

There are currently no comments for this question.

Other Answers (1)

  • Naveen N by Naveen N
    Member since:
    March 07, 2008
    Total points:
    216 (Level 1)
    take percent as double data type;

    int x, t;
    double p;
    scanf("%d%d",&x,&t);
    p=(x*100)/t;
    printf("%f", p);

Answers International

Yahoo! does not evaluate or guarantee the accuracy of any Yahoo! Answers content. Click here for the Full Disclaimer.

Help us improve Yahoo! Answers. Send Feedback