simple percentange Calculation
Please take a look at the following code and tell me why skillPercentange is always Zero:
NSInteger skillPercentange;
skillPercentange=totalCorrectAns开发者_如何学编程 * reloader/100;
I don't know exactly what you want to do, but I'll try to show you a demo:
int allQuestions = 50;
int correctAnswers = 25;
float precentage = (100 * correctAnswers)/allQuestions;
NSLog("%i of %i questions answered correctly. That are %.1f percent!",correctAnswers,allQuestions,precentage);
Output: "25 of 50 questions answered correctly. That are 50.0 percent!"
float skillPercentange;
skillPercentange=(totalCorrectAns * reloader)/100;
or
skillPercentange= totalCorrectAns * (reloader/100);
according to whatever is your formula.
NSLog(@"skillPercentange=0.1f",skillPercentange);
NSInteger skillPercentange;
skillPercentange = 100 * totalCorrectAns / reloader;
精彩评论