Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ please include screenshot, thanks Common User Error A common user error is to input character data when numeric data is requested. This error may

C++ please include screenshot, thanks

Common User Error

A common user error is to input character data when numeric data is requested. This error may cause a program to react unpredictably.

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions

Question

Describe the role of the stakeholder, and list several examples.

Answered: 1 week ago

Question

Find a unit vector u in the direction opposite of (-3, -8, -6). u =

Answered: 1 week ago