Input validation loop in C++ with strings -


I'm just learning C ++ (1 week experience) and trying to write an input validation loop The user asks "yes" or "no", I know this, but it is feeling that there is a better way to reach it. Here's what I came with:

  {Four floors [5]; // To store input in a string int test; // While testing in a Loop Cot & lt; & Lt; "Yes or no \ n"; Cin.getline (temp, 5); | (| (SRCMP (Temporary, "Yes")) || | (SRCMP (Temporary, "No")) // Checks the string if yes or no C & lt; & Lt; "Acceptable input"; // displays that if the string is not really yes or any other, / if not, then check the input validation loop {test = 0; While (trial == 0) // loop {cout & lt; & Lt; "Invalid, try again. \ N"; Cin.getline (temp, 5); // Yes or no attempt to get it again (! (Strcmp (temp, "yes")) || (strcmp (temporary, "no"))) / or checks the string yes or no test = 1 ; // check changes 1 so that the loop can be canceled test = 0; // 0 so that the loop is rewritten and ask for a valid input again; cout & lt; & Lt; "Acceptable input"; } Cin.ignore (); Cin.get (); Return 0; }   

I apologize for my poor notes, it is not certain what is relevant. I'm also using cstring header

I think you want a while while loop :

  bool test = false; Do {cout & lt; & Lt; "Yes or no \ n"; Cin.getline (temp, 5); If (yes! Or (cf. & lt; & lt;) (if (strcmp (temp, "yes")) || | (strcmp (temp, "no")) / / "acceptable input" ; // displays that the string is actually yes or not test = true;} and {cout    

Comments