I am making a simple program, where user needs to enter a few possible characters. I want possible inputs to be only i, c, l, v, h, k, f, s, x. I do realize I can do something like:
char a;
bool s(false);
cin>>a;
do
{
switch(a)
case 'i': ...
case 'c': ...
...
default: cout<<"Invalid input! Try again: "; cin>>a; s=true;
} while(s);
However, I am pretty sure there is a more gracious solution. I am guessing enumerations would be involved. Would anyone be so kind as to tell it to me, since I could not find absolutely anything on the subject.
Aucun commentaire:
Enregistrer un commentaire