So, I need to find a way to create a way for the computer to ask for input, for this example lets make it 1 and 2. 1 for yes and 2 for no.

int yes;
int no;

cout << Do you like orange chicken?" << endl;
cout << endl << "1 - Yes" << endl;
cout << "2 - No\n- ";

So my question is, if the user enters K or a char value, how do i get it to ask again? I've been trying to do this inside a do while loop and through a switch statement. I tried in an IF ELSE statement but i couldn't get CIN to register. I know you have to clear CIN after the loop with...

cin.clear();

Then i can get it to ask it again if what the wrong input the user put in was an int value. When the user enters a Char value, every time it goes into a infinite loop...

So if you could be so kind as to post some code that shows me how to do it and explain it that would be great. Thanks =)

#include <iostream>

int main ()  {
   static const char y='y';
   static const char n='n';

   char answ;
   bool rep=1;


   while (rep)  {
      std::cin >> answ;      
      switch (answ)  {
         case y:
            std::cout << "ok";
            rep=0;
            break;
         case n:
            std::cout << "no";
            rep=0;
            break;
         default:
            rep=1;
            break;
       }
    }
 }
commented: One more post with full working code and you will get an infraction -3

That was it, thanks VERY VERY much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.