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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:23:26+00:00 2026-05-26T01:23:26+00:00

Here I set up a while loop where I input a selection number 1

  • 0

Here I set up a while loop where I input a selection number 1 or 2. If I choose 1 or 2 it couts the 1 or 2 whatever I choose; if I choose a number below 1 or above 2 it goes to the else statement which asks the user to input again. But if the user inputs the problem is that it won’t loop back to the beginning if they choose the right number 1 or 2; it will just end the loop there and not go to the correct if clause. Why is this? I feel as though I attacked it right.

int menus (int selection)
{
    while ( selection > 2 ||  selection < 1)
    {
        if (selection == 1)
        {
            cout << " 1 " << endl;
        }
        if (selection == 2)
        {
        cout << " 2 " << endl;
        }
        else
            cout << "You didnt choose 2 or 3. Choose again";
        cin >> selection;
    }
    return 0;
}
  • 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-26T01:23:27+00:00Added an answer on May 26, 2026 at 1:23 am

    If you enter 1 or 2, it won’t even enter the loop as neither 1 or 2 are either bigger than 2 or smaller than 1, they are equal.

    This should fix it:

    while ( selection >= 2 ||  selection <= 1) //equals while(true)
    

    Note that you should also use an else if statement at the second if, it doesnt work correctly the other way.

    else if (selection == 2)
    {
        cout << " 2 " << endl;
        break; // this leaves the loop
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the scenario: I have a set of buttons that I want to bind
Here's the situation: I have a label's text set, immediately followed by a response.redirect()
Let me set the stage here. I'm a very junior developer who's recently made
Here is pseudo-code of how I setup an array representing the MandelBrot set, yet
Here's my scenario: I have a simple stored procedure that removes a specific set
In my environment here I use Java to serialize the result set to XML.
Here's the problem I'm having, I've got a set of logs that can grow
My objective here is really simple -- I'm trying to set an NSString to
So here is the simple code: [System.ComponentModel.DefaultValue(true)] public bool AnyValue { get; set; }
Here's a minimal batch file, demo.bat , to illustrate my problem: @ECHO off set

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.