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 7439105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:39:29+00:00 2026-05-29T10:39:29+00:00

I am doing a quiz and testing the user. If the user is wrong

  • 0

I am doing a quiz and testing the user. If the user is wrong he is allowed a second chance or skip, if he chooses 2nd chance and is wrong again, the game is over. How do I break out of this loop to end the game? I tried a do while loop,

do { stuff} while (wrong<2) while counting ++wrong;

every time he’s wrong, but didnt work.

I have labeled the ++wrong with // statements below

void player_try (string questions[][5], char answers[])
{
    char user_guess;
    int m = 0;
    srand(time(NULL));
    int x;
    int choice;
    int wrong =0;

    for (m=0; m<7; m++)
    {
        do
        {
            x = (rand() % 7);
            cout << user_name << ": Here is question number " << m+1 << endl;
            cout << m+1 << ". " << questions[x][0]<< endl;
            cout << "A. " << questions[x][1]<< endl;
            cout << "B. " << questions[x][2]<< endl;
            cout << "C. " << questions[x][3]<< endl;
            cout << "D. " << questions[x][4]<< endl;
            cin >> user_guess;
            user_guess = toupper(user_guess);

            while (!(user_guess >= 'A' && user_guess <= 'D'))
            {
                cout << "Please choose a valid answer.";
                cin>> user_guess;
            }
            if (user_guess != answers[x])
            {
                cout <<"Wrong!" <<endl;     
                ++wrong;    // THIS IS WHERE I COUNT WRONG ONCE
                cout << "Skip this question or take a chance at greatness?"      << endl;
                cout << "Press 1 to skip, press 2 to take a chance at greatness" << endl;
                cin  >> choice;
                if (choice == '1')
                {
                    cout << "we shall skip this question." << endl;
                }
                else
                {
                    cout << "I applaud your bravery." << endl;
                    cout << user_name << ": Here is question number " << m+1 << endl;
                    cout << m+1 << ". " << questions[x][0]<< endl;
                    cout << "A. " << questions[x][1]<< endl;
                    cout << "B. " << questions[x][2]<< endl;
                    cout << "C. " << questions[x][3]<< endl;
                    cout << "D. " << questions[x][4]<< endl;
                    cin >> user_guess;
                    user_guess = toupper(user_guess);

                    while (!(user_guess >= 'A' && user_guess <= 'D'))
                    {
                        cout << "Please choose a valid answer.";
                        cin>> user_guess;
                    }
                }
                if (toupper(user_guess) != answers[x])
                {
                    cout <<"Wrong!" <<endl;
                    ++wrong;;  // THIS IS WHERE I CANT WRONG TWICE
                }
                else
                {
                    cout << "correct!" << endl;
                }
            }
            else
            {
                cout << "correct!" << endl;
            }
        }
        while(wrong < 2);
    }
}
  • 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-29T10:39:30+00:00Added an answer on May 29, 2026 at 10:39 am

    Change your function return type to an integer. That simply means changing “void” to “int.”
    Then, inside the function place a return 0; at the point you want your function to terminate. Be sure you include another return 1; for the case that the user wins too.

    This is how the main() function works. Consider:

    int main() 
    {
      string tester = "some string";
      if(tester == "some string")
        return 1;
    
      cout << "Hey!"
      return 0;
    }
    

    In the above case, main() terminates at the “return 1;” because the if statement was TRUE. Note that “Hey!” is never printed. It’ll work the same way for your function.

    As a plus, you can use that return value to let OTHER functions (such as main()) know if the function terminated because the user won (it returned 1), or lost (it returned 0).

    Yes, a break statement is also a valid way to terminate the loop, but I submit that this method is the safer, cleaner way to go about it. In general, we like to know whether a function or program was successful or not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing a C++ quiz and I need to say whats wrong in the
I am doing a simple Quiz application that has several questions that the user
I am doing an Online Quiz project in C#. The test client is a
There's an open book quiz for a job application I'm doing, and it's obviously
i am trying to generate random number for my mental math quiz game. But
Doing some code in JavaScript/jQuery and I need to have it where the user
Basically I am doing a quiz app, I need to dedicate one question to
I have a problem, I'm creating a quiz game and have a few questions
I am doing a quiz application and I would like to know what's the
I am making a basic quiz program, that when finished will allow the user

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.