Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this questionI have a quiz that have many questions and 5 possibili开发者_如何学Goties of answers.
Lets take one question,it has follow answers:
148 - Good
5 - N/A
268 - Great
5 - Regular
11 - Bad
These are numbers collected directly from database.Now i need to show it as percentage.i.E:
Great - 45%
Good - 40
[..] and so on
Any ideas?
int na = 5;
int good = 148;
int great = 268;
int regular = 5;
int bad = 11;
int sum = na + good + great + regular + bad;
naPercent = getPercent(na,sum);
float getPercent(int value, int sum)
{
return (value*100.0)/sum;
}
This is not a programming question, it is a math question. The percentage of each item is equal to the number of that item divided by the total number. In your example, the total number is 148+5+268+5+11 = 437. Great = 268 / 437 = 61.327%
total count for the answer / total count for all answers to this question combined * 100
精彩评论