Я пишу программу викторины. У меня есть одномерный массив правильных ответов из текстового файла, который я должен сравнить с users_guess
, чтобы проверить, верна ли его догадка. Я должен выплюнуть 6 случайных вопросов.
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
}
}
Моя проблема в том, чтобы связать множество вопросов с массивом ответов. Кроме того, завершение программы, если он дважды ошибается. что вы все думаете?