-5

I am trying to display a percentage to the user at the end of my exam. Essentially I need a line of code that divides myScore by the total amount of questions which is 70. Any help would be GREATLY appreciated.

Here is my code for the end of the exam:

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];

}
4

1 回答 1

0

The division operator in c (and thus Objective-C) is /.

myScore * 100 / 70
于 2013-05-16T16:43:56.777 回答