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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:52:48+00:00 2026-05-18T00:52:48+00:00

I posted a question about how to get user input such as YES or

  • 0

I posted a question about how to get user input such as YES or NO to control the flow of a program using if else statements, I got a answer and now i’m a step closer to making this work, however another problem has arisen, i really need to allow for multiple inputs, for example this is what im trying:

if (input == ("YES" || "yes" || "y" || "Yes" || "Y"))
{
    cout << "you said yes" << endl;
}
else if (input == "NO", "no", "n", "No","N")
{
    cout << "you said no" << endl;
}
else 
{
    cout <<  "ERROR!!!" << endl;
}

Kiril Kirov posted this code that could help:

if( std::string::npos != input.find( "no" ) )

but i couldn’t get it to work, and roger pate suggested this:

if (prompt && cin.tie()) {
*cin.tie() << prompt << (default_yes ? " [Yn] " : " [yN] ");

however i never tried this as its complexity is far beyond my understanding. i was hoping for a solution a beginner programmer could understand or maybe im just a really slow learner


EDIT:
I made this modification but it still doesn’t work any better then before, if i give the wrong case it goes to else (error) and there is no where to add more words, (such as NO N no No) :

cout << "\nYES or NO" << endl;
string input ="";
cin >> input;

if ( std::string::npos != input.find( "yes" ) )
{
    cout << "you said yes" << endl;
}
else if ( std::string::npos != input.find( "no" ) )
{
    cout << "you said no" << endl;
}
else 
{
    cout <<  "ERROR!!!" << endl;
}
  • 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-18T00:52:48+00:00Added an answer on May 18, 2026 at 12:52 am

    Add the headers

    #include <algorithm>
    #include <cctype>
    
    cout << "\nYES or NO" << endl; 
    string input =""; 
    cin >> input; 
    transform (input.begin(), input.end(), input.begin(),tolower);
    
    if ( (std::string::npos != input.find( "yes" )) || (std::string::npos != input.find( "y" )) ) 
    {
         cout << "you said yes \n" ; 
    }
    else if ( (std::string::npos != input.find( "no" ) )  || (std::string::npos != input.find( "n" ) ) )
    {
        cout << "you said no \n" ; 
    }
    else  
    {
        cout <<  "ERROR!!! \n" ; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

earlier i posted a question about cin skipping input, and I got results to
I posted a question here last week about using Ajax with J2EE and got
I posted a question about keys yesterday, and got very helpful responses. I've been
Recently I posted a question about the html helper dropdownlist and got it working
I have previously posted a question about this but I did not get an
I just posted a question about how to get a delegate to update a
Yesterday I've posted question about SQLite performance issues ( Terrible performance in Zend Db
I recently posted a question about screen rotation in my live wallpaper. To test
I just posted a question about whether WPF is a good choice for a
I have posted a question about multilanguage database design here, [] What are best

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.