Question: Write a program in C++ that prompts the user to enter a length in inches and outputs the equivalent length in centimeters. If the user

Write a program in C++ that prompts the user to enter a length in inches and outputs the equivalent length in centimeters. If the user enters a negative number, throw and handle an appropriate exception and prompt the user to enter another number.

Begin by writing the declaration of a user-defined exception type named NegativeNumber

Write a function called ConvertToCentimeters. The function converts the number of inches sent to the function through the parameter list to centimeters ( 2.54 centimeters = 1 inch) unless the input value is a negative number, in which case a NegativeNumber exception is thrown.

Within the main function, write a try-catch statement within a while loop that prompts for and inputs the number of inches (type double) from the keyboard. The try-catch statement calls the ConvertToCentimeters function and outputs the value returned from the function. If a NegativeNumber exception is thrown, print an error message.

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!