0

So here in my code:

#include <iostream>    
using namespace std;

int main ()
{    
    int choice;    
    cout<<"Make a choice\n";    
    cin>>choice;    
    cin.ignore();    
    while ( choice != 5 ) {    
        cout<<"Make a different choice!\n";    
        cin>>choice;    
        cin.ignore();    
    }
    cout<<"You weren't supposed to enter 5!";        
}

This works fine for entering in numbers, but whever I enter a string (i.e. a), the program simply writes

"Make a different choice!\n"

and infinite number of times! How do I handle a possible string input for choice?

2
  • Also see this stackoverflow.com/a/10829026/1870232 Commented Nov 8, 2014 at 15:02
  • is answered there yes, but the "answer" marked is not what I was looking for, nor was the question what I was asking, so I had ignored it. Thanks (do i mark this answered or something?) Commented Nov 9, 2014 at 8:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.