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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:45:40+00:00 2026-06-13T07:45:40+00:00

I am getting into c++ right now, and right now I want to know

  • 0

I am getting into c++ right now, and right now I want to know the most common/best way to catch invalid input. I would love answers to this wide open question, but my more specific question is as follows.

I want a char from the user. If the char is ‘y’ then it will repeat, if it is ‘n’ then the program will close. If I enter multiple chars then it will repeat as many times as chars e.g. I enter ‘hello’ it will show my output 5 times. I assume that it reads each char and goes through the whole loop then reads the next char in line. How can I get it to show up just one time?

bool valid = 0;
while(valid)
{

...

    bool secValid = 0;
    while(secValid == 0)
    {
        cout << "To enter another taxable income type 'y': \n\n";
        char repeat = NULL;
        cin >> repeat;
        if(repeat == 'y')
        {
            valid = 0;
            secValid = 0;
            system("cls");
        }else if(repeat == 'n')
        {
            return;
        }else
        {
            secValid = 1;
        }
    }
}
  • 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-13T07:45:41+00:00Added an answer on June 13, 2026 at 7:45 am

    std::getline():

    std::string line;
    std::getline(std::cin, line);
    if (line == "y") {
       // handle yes
    }
    else if (line == "n") {
       // handle no
    }
    else {
       // handle invalid input
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i'm getting into security problems right now, and i want to know what
Just getting into SQL stored queries right now... anyway, here's my database schema (simplified
I am interested into getting into bash scripting and would like to know how
What is the best way to load content into my infowindow using ajax? Right
I created this html : %a.btn.btn-large.btn-primary.getting-started %i.icon-arrow-right.icon-white = t('header.getting-started') Now, i want to specify
I'm a C# (WinForms) developer and I'm now getting into MVC3. I want to
Without getting into to much detail about the actual program,I want to take an
Now i JUST started getting into joins, so I'm probably missing some core understanding
I am right now getting myself more and more familiar with Zend Framework 2
I'm trying to attempt something that seems super simple, but right now I want

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.