-2

I'm trying to add a retry button in a mini quiz game, that reshow the view (question generator), but I want to exclude the last answered question from the random generator

-(IBAction)continueQuestion:(id)sender{

[self startQuestions];

}

This code doesn't work though my questions are like this

switch (questionNumber) {
    case 0:
        questionText.text=[NSString stringWithFormat:@"Question 1"];
        rightAnswer=8;
        break;

    case 1:
        questionText.text=[NSString stringWithFormat:@"Question 2"];
        rightAnswer=64;
        break;

    case 2:
        questionText.text=[NSString stringWithFormat:@"Question 3"];
        rightAnswer= 10.2;
        break;


    default:
        break;}
}

}

- (void)viewDidLoad{
questionNumber=arc4random() %3;

[self startQuestions];}

So for example if Question 1 was asked and answered, I want it not to be included in the random generation of the next question

Thanks,

Binarian
  • 12,296
  • 8
  • 53
  • 84
  • Add some code to your question plz ! – Rudi Jun 07 '14 at 07:31
  • Do you want to hide the button on last answered question? You can do that by `button.hidden=YES`? – Amar Jun 07 '14 at 07:33
  • @Amar, I want to add a button that regenerate the view (New Question) but will exclude the last answered question from the random selection – user3717316 Jun 07 '14 at 07:38
  • @user3717316 Okay, wouldn't hiding the button on the view work? You need to check if it is the last answered question getting displayed. If not hide button. – Amar Jun 07 '14 at 07:40
  • I tried that ! but if I just hide the button it will keep the same last question , and if I add hide button to the method startQuestion it might bring back the same question by random selection , and it the code doesn't really working either way *check the code in the topic please – user3717316 Jun 07 '14 at 07:42

1 Answers1

0

What you need is an NSMutable array to store questionNumbers for all answered questions. You need to write to this array whenever you get a correct answer in your startQuestions() method.

Then in your viewdidload(), check if the random number generated is in this array, if it is then call viewdidload() again. Otherwise call startQuestions.

Zaxter
  • 2,939
  • 3
  • 31
  • 48