Description
The purpose of this challenge is to use the IF-ELSE-IF and SWITCH statements for controlling program flow. This challenge simulates a life insurance application.
Requirements
- Ask the user to enter their first name
- Ask the user to enter their last name
- Ask the user for their age on their next birthday
- Ask the user if they have used tobacco in the last 5 years. (Hint: Use a char variable and ask a yes/no question)
- If the user answers yes to question 3 above, display a message recommending another company. Otherwise, continue and ask the user more questions (see below)
- Ask the user what kind of life insurance the user is applying for (term life, whole life, universal life). You must use a switch statement to display a friendly message about the selected life insurance type. (Hint: Use a char variable entered by the user indicating their selection).
- Insurance premiums will cost $20 a month if applicant is 25 years old or younger. Applicants between 26 and 35 will be charged $30 a month. Applicants between 36 and 45 will be charged $45 a month. Applicants between 46 and 55 will be charged $55 a month. Any applicants older than 55 will be charged $150 a month. You must use an if-else-if statement to determine the appropriate monthly premiums.
- Additionally, if the user selects any other type of insurance other than Term Life, then monthly premiums will cost an additional $50 across all age ranges. (example, if 25 years or younger, the premium for whole life or universal life will be $70 instead of $20).
- Ask the user if they are male or female. Male users will incur an additional 12.5% on top of the monthly premium.
- Display the monthly premium to the user based on age, life insurance type and gender.
DO NOT USE
You may not use any looping mechanisms or user-defined functions.
Sample Interaction / Output
Your family is precious to us - let's get you insured. Please enter your first name to begin your application: Michael And your last name: Reed Thank you, Michael Reed, how old will you be on your next birthday? 27 Have you used tobacco in the last 5 years (y/n)? y Sorry, we don't offer services for tobacco smokers. Please call our sister company RISKYBIZ at 800-MOR-RISK
RUN IT AGAIN:
Your family is precious to us - let's get you insured. Please enter your first name to begin your application: Rich And your last name: Mann Thank you, Rich Mann, how old will you be on your next birthday? 38 Have you used tobacco in the last 5 years (y/n)? n We have three types of insurance available: T - Term Life W - Whole Life U - Universal Life What kind of life insurance are you applying for? W Whole Life? Great choice! Please indicate your gender (m/f): m Rich Mann, your monthly premium for Whole Life based on your age of 38 will be $106.88 per month.
In the sample interaction above, the monthly premium is calculated as below:
+ $45 (based on applicant’s age)
+ $50 (for Whole Life type)
+ $11.88 (12.5% of $95 as a male applicant).
= $106.88 per month
Make sure you test your code with various combinations of ages and life insurance types.
Hints
- It’s good practice to initialize variables to default values that make sense (for example, set premium to 0.00)
- Include the <iomanip> header file. This will allow you to use various options to format your output such as setprecision
- Include the code below before any other cout lines. The setprecision(x) will display your decimal output with x decimal places.
cout << fixed << setprecision(2);
LEGEND
PROGRAM OUTPUT
USER ENTRY
FROM INPUT
CATALOG ID: CPP-FLOW0004
Print Requirements