简单的百分比计算

soh*_*_ju 3 objective-c

请看下面的代码并告诉我为什么skillPercentange总是为零:

NSInteger skillPercentange;
skillPercentange=totalCorrectAns * reloader/100;
Run Code Online (Sandbox Code Playgroud)

Fab*_*oni 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);
Run Code Online (Sandbox Code Playgroud)

输出:"正确回答了50个问题中的25个.这是50.0%!"