So I’m trying to make a simple application that quizzes the user. It asks a question and the user answers 1, 2, 3, or 4. The app then takes that answer and if it is correct adds +1 to the total_score which will be displayed at the end. Everything looks sound to me, but when I run it and I get to the if (q1_valid == false) part it skips the cout and runs the goto no matter if q1_valid is true or false.
#include <iostream>
using namespace std;
int main()
{
int q1_answer;
int total_score;
bool q1_correct;
bool q1_valid;
Question_1:
cout << "Question 1 (#3 is correct)" << endl;
cout << "1.) Answer 1" <<endl;
cout << "2.) Answer 2" <<endl;
cout << "3.) Answer 3" <<endl;
cout << "4.) Answer 4" <<endl;
cin >> q1_answer;
if (q1_answer == 1)
q1_correct = false;
q1_valid = true;
if (q1_answer == 2)
q1_correct = false;
q1_valid = true;
if (q1_answer == 3)
q1_correct = true;
q1_valid = true;
if (q1_answer == 4)
q1_correct = false;
q1_valid = true;
if (q1_valid == false)
cout << "Invalid answer." <<endl;
goto Question_1;
if (q1_correct == true)
cout << "Correct!" <<endl;
(total_score + 1);
goto Question_2;
if (q1_correct == false)
cout << "Incorrect." <<endl;
goto Question_2;
if (q1_valid == false)
goto Question_1;
Question_2:
cout<< "Q2" <<endl;
cin.ignore();
cin.ignore();
}
I have a few tips here: