Question: in C++ this program will determine, based on the age input, whether the user is old enough to vote for this program, you will use
in C++
- this program will determine, based on the age input, whether the user is old enough to vote
- for this program, you will use the try and catch method to deal with errors in inputted data
- under try:
- create an if, else decision structure to determine
- if the user is old enough to vote (age greater than or equal to 18)
- if their age is less than 18
- send them to another function, called tooYoung and pass age to it
- tooYoung function will test whether the age is less than zero
- if it is, it will trigger a string exception which says: "ERROR: Cannot have a negative age!"
- otherwise, the tooYoung function will return the number of years until the user is 18
- assign the returned value from the function to an integer variable called years
- display the returned value in a sentence that says: "You will be old enough in "">
- the catch part of the main function will call out the same exception string that is listed in the tooYoung() function.
- save and test your program with a negative number, a number between 0 and 17, and a number 18 or greater.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
