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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:34:41+00:00 2026-06-09T08:34:41+00:00

Below is the code for a simple menu in C++. For some reason, if

  • 0

Below is the code for a simple menu in C++. For some reason, if you give it garbage input it will react properly (“Please try your selection again”). However it will then go through the loop one more time giving the error message again, and then finally go back to functioning like normal.

EDIT

The input variable is a char. If the garbage input is only one character long, then the loop works as it is supposed to. If there are any additional characters that will result in the loop being executed more than once before the user is allowed to input anything again.

char input = 0;
    while (input != 4)
{
    cout << "1. Circle";
    cout << "\n2. Rectangle";
    cout << "\n3. Triangle";
    cout << "\n4. Quit";
    cout << "\nChoose a shape: ";
    cin >> input;

    switch(input)
    {
    case '1':
        circleFunctions();
        break;
    case '2':
        rectangleFunctions();
        break;
    case '3':           
        triangleFunctions();
        break;
    case '4':
        exit(4);
    default:
        cout << "\nPlease try your selection again...\n";
        input = NULL;
        cin.ignore();
        break;
    }

    cin.ignore();
    cout << "\n";
}
  • 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-09T08:34:43+00:00Added an answer on June 9, 2026 at 8:34 am

    Found the answer. Adding the following parameters to cin.ignore made it work:

        cin.ignore(20, '\n');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The above code does not work properly. I need to implement a simple menu
I have simple unordered list menu. Code is below or you can grab it
Below is some code I am working on for a navigation menu, if you
The below code is very simple. I have a jQuery autocomplete bound to an
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
I am testing this simple code below and it works... $(document).ready( function() { $('.show-modal').click(
The simple code block below can be served up in a static HTML page
I am using the below code snippet to FTP simple text files from a
The code below is for a simple newsletter signup widget. I'm sure there's a
Below is my code for a simple form in the create_session.php page. I am

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.