Programming Questions? Ask a Programmer for Answers ASAP
Thanks for using JustAnswer. This is Leela and I will help you with the question today.
You can use cin.fail() to prompt user for valid input. It can be done as follows.
The below function shows an example of how to get a valid int from user, also prompt till user enter a valid int. You can refer the same and use in your program.
cin >> val;
cout << "You entered a value of the wrong type!" << endl;
cout << "Enter a int : " << endl;
Hope this helps.
Please let me know if there are any further queries.
I can help you with any computer science related subjects concepts understanding via one-on-one skype sessions, programs, latest technology happenings, etc.
All the best.