请查看以下代码并告诉我为什么skillPercentange始终为零:
NSInteger skillPercentange;
skillPercentange=totalCorrectAns * reloader/100;
答案 0 :(得分:12)
我不确切地知道你想做什么,但我会试着给你看一个演示:
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);
输出:“50个问题中有25个问题正确回答。这是50.0%!”
答案 1 :(得分:1)
float skillPercentange;
skillPercentange=(totalCorrectAns * reloader)/100;
或
skillPercentange= totalCorrectAns * (reloader/100);
根据你的公式。
NSLog(@"skillPercentange=0.1f",skillPercentange);
答案 2 :(得分:0)
NSInteger skillPercentange;
skillPercentange = 100 * totalCorrectAns / reloader;