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?

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
Matthew
  • 672
  • 4
  • 11
  • Also see this http://stackoverflow.com/a/10829026/1870232 – P0W Nov 08 '14 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?) – Matthew Nov 09 '14 at 08:35

0 Answers0