Percent in c++?

Follow
  • Follow publicly
  • Follow privately
  • Unfollow
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
Best AnswerAsker's Choice
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.

Asker's rating & comment

5 out of 5
Thanks. Exactly as I needed, works perfect. :D
  • 3
  • Comment

Other Answers (1)

  • Naveen N answered 6 years ago
    take percent as double data type;

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

    to add your answer

Who is following this question?

    %
    BEST ANSWERS
    Member Since:
    Points: Points: Level
    Total Answers:
    Points this week:
    Follow
     
    Unfollow
     
    Block
     
    Unblock