Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started