Quiz app


#1

Im having an issue. I can click the aster button and it displays an answer 14 no others. When I click the question button it does nothing. I have the labels set correctly or at least they are set the same (questionField and answerField). the buttons same (showAnswer and showQuestion)

any ideas on what I have done wrong.

@interface QuizViewController : UIViewController

//START CODE
{
int currentQuestionIndex;

//the model objects
NSMutableArray *questions;
NSMutableArray *answers;

//the view objects - dont worry about IBOutlet

//Well talk about it shortly

IBOutlet UILabel *questionField;
IBOutlet UILabel *answerField;

}

-(IBAction)showQuestion:(id)sender;
-(IBAction)showAnswer:(id)sender;

//END CODE

//START CODE

-(id)initWithNibName:(NSString *)nibNameOrNil

bundle:(NSBundle *)nibBundleOrNil
{

//call the intit method implemented by the superclass

self = [super initWithNibName:nibNameOrNil
                       bundle:nibBundleOrNil];

if (self) {
    
    //create two arrays and make the pointers point to them
    
    questions=[[NSMutableArray alloc] init];
    answers=[[NSMutableArray alloc] init];
    
    //adding questions and answers to the arrays
    [questions addObject:@"what is 7+7?" ];
    [answers addObject:@"14"];
  
    [questions addObject:@"what is the capitol of Vermont?" ];
    [answers addObject:@"Montpelier"];
    
    [questions addObject:@"From what is cognac made?" ];
    [answers addObject:@"Grapes"];
    
    
}
        //return the address of the new object
return self;

}

-(IBAction)showQuestion:(id)sender
{
//step to the next question
currentQuestionIndex++;

//am I past the last question?

if (currentQuestionIndex == [questions count]){

    //go back to the first question
    currentQuestionIndex = 0;

    
}

//get the string at that index in the questions array
NSString *question=[questions objectAtIndex:-currentQuestionIndex];

//log the string to the console
NSLog(@"displaying question: %@", question);

//clear the answer field
[answerField setText:@"???"];

}
-(IBAction)showAnswer:(id)sender

{
//What is the current question
NSString *answer = [answers objectAtIndex:currentQuestionIndex];

//display it in the answer field
[answerField setText:answer];

}

//END CODE


#2

remove the - in front of currentQuestionIndex in showQuestion:'s [questions objectAtIndex:-currentQuestionIndex]


#3

Thank you