[Solved] Validation in a C++ Program [closed]

You can test for input success with an if:

if (cin >> ch)

To ask the user to enter input again, you’ll need a loop, and you also need to call cin.clear() to restore the stream’s state:

cout << "\n     Enter your choice(1,2,3,9)":

cin >> ch;
while (!cin)
    cout << "Invalid input. Please try again." << endl;

    cin >> ch;

That’s how you’d handle the first input item in main. You can do something similar for the others.


solved Validation in a C++ Program [closed]