I’m writing a quiz program. I have a 1-Dimensional array of correct answers from a text file, which I must compare to a users_guess to check if his guess is correct. I must spit out 6 random questions.
string questions[50]; // 50 questions
char answers[50]; // 50 correct answers
int i = 0;
char user_guess;
int rand_index = rand() % 10; //generate random number
for (i=0; i<6; i++) //loop for 6 questions
{
cout << questions[rand_index] << endl;
questions[rand_index] = answers[] // i need help. how do i compare the arrays?
cin >> user_guess;
if (user_guess != answers[]) // if he's wrong
{
cout << "sorry. try again" << endl;
cout << questions[rand_index] << endl; // 2nd chance
cin >> user_guess;
if (user_guess!= answers[]) // wrong again
{
cout << "you lose.game over." << endl; //game over
break; // does this cancel the game all together?
}
else
{
cout << "good job!" << endl;
i++; // on to the next round
}
}
else
{
cout << "good job!" << endl;
i++; // on to the next round
}
}
my trouble is getting the array of questions hooked up with the array of answers. Also, ending the program if he’s wrong twice. what do you all think?
Note: you increment once after good job, and again in the for loop, so you’ll be counting by twos.