Question: In C++ Please include screenshots Write a function called getnum() that accepts a value, verifies it is numeric, and returns it. If the user inputs

In C++ Please include screenshots

Write a function called getnum() that accepts a value, verifies it is numeric, and returns it. If the user inputs a non-numeric input, the program should recover from the error status and throw an exception.

In the main function, write a try...catch clause which uses the getnum() function to obtain an integer value. If the user inputs character data, the program should use the catch to display an error message. The program should loop until a numeric response is given by the user.

Hints:

If the program executes a cin statement with an integer variable and the user inputs character data, the statement evaluates as false. So, an easy check for numeric data might use the if statement: if (cin >> num)... This check will detect invalid character data. This check will not detect if a decimal value was entered.

Research the cin.clear() and cin.ignore() statements. If an input results in an error state, the programmer

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!