試験の最後にパーセンテージをユーザーに表示しようとしています。基本的に、myScore を質問の総数である 70 で割るコード行が必要です。
試験終了時のコードは次のとおりです。
NSInteger endOfQuiz = [theQuiz count];
if((((questionNumber - 1) * 6) + 6) == endOfQuiz)
{
// Game is over.
if(myScore >= 49 )
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Practice Exam concluded. Congratulations, you have passed with a 70%% or better! \nYou scored %i out of 70!", myScore];
theQuestion.text = finishingStatement;
answerResult.text = @"";
counterLabel.text = @""; }
else
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Practice Exam concluded. Unfortunately, you have failed with less than 70%%, keep practicing! \nYou scored %i out of 70.", myScore];
theQuestion.text = finishingStatement;
counterLabel.text = @"";
}
theLives.text = @"";
answerResult.text = @"";
// Make button 1 appear as a reset game button
restartGame = YES;
[answerOne setHidden:NO];
[answerOne setTitle:@" Try this Practice Exam again" forState:UIControlStateNormal];
}