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

  • SEARCH
  • Home
  • 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 9016473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:00:26+00:00 2026-06-16T04:00:26+00:00

I need to figure out how to validate 2 conditions. Check if a previous

  • 0

I need to figure out how to validate 2 conditions.

  1. Check if a previous number has been played.
  2. Check if the number is between 1 and 9.

In either case, it should loop back to the beginning. With the first situation, it shouldn’t run till the user enters a number that hasnt been played.

do
{
  cout << "Interesting move, What is your next choice?: ";
  cin >> play;
  Pused[1] = play;

  if(play != Pused[0] && play != cantuse[0] && play != cantuse[1] )
  {
    switch(play)
    {
      default:
        cout << "Your choice is incorrect\n\n";
        break;
    }   
  }
}while(play != 1 && play != 2 && play != 3 && play != 4
    && play != 5 && play != 6 && play != 7 && play != 8 && play != 9);

Dis_board(board);
  • 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-06-16T04:00:27+00:00Added an answer on June 16, 2026 at 4:00 am

    Instead of do-while loops, i like to use the combination of infinite loops + break statements, like this:

    cout << "What is your first choice? ";
    while (true)
    {
        // Input the choice, including validation
    
        // Do the move
    
        if (game_over)
            break;
    
        cout << "Interesting move; what is your next choice? ";
    }
    

    In the code above, the two comments represent code, which may itself contain loops. In order to reduce confusion, you might want to stuff this code into a separate function. For example, to input the choice:

    while (true)
    {
        cin >> play;
        bool is_illegal =
            play == cantuse[0] ||
            play == cantuse[1] ||
            play < 1 ||
            play > 9;
        if (is_llegal)
            cout << "Your choice is incorrect; please enter again: ";
        else
            break;
    }
    

    Note: to implement good handling of user errors, you also have to account for the case when the user enters nonsense instead of a number; look up istream::ignore and ios::clear for that.

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

Sidebar

Related Questions

From the following HTML I need to figure out which List tag has class
I need validate multiple fields in the JavaScript Framework, but can't figure out how.
I need to figure out a way to set ValidateRequest at model...I understand that
I need to figure out a way to insert a record with a java.util.Date
I need to figure out the size of a remote file before I download
So i need to figure out how i can get a record count value
I understand that I need to figure out my own homework, but seeing that
I have a piece of code where I need to figure out if a
I am optimizing an algorithm in ARM assembly and need to figure out in
I am making adobe air desktop app. I need to figure out how to

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.