Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5962977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:10:55+00:00 2026-05-22T19:10:55+00:00

So I’m trying to make a simple application that quizzes the user. It asks

  • 0

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();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:10:56+00:00Added an answer on May 22, 2026 at 7:10 pm

    I have a few tips here:

    1. If… then is a conditional, not a loop. Sorry, that’s just me being slightly picky. 😉
    2. Never, ever, ever, ever use goto. ADVANCED USAGE: only use goto when there’s a damned good reason to.
    3. When testing boolean values, you don’t need “== true” or “== false”.
    4. It looks like you haven’t learned how to use the else statement yet. That’s going to make your program a lot easier to read, debug, and understand.
    5. Brackets are also necessary, as noted above.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.