Flow Control 4

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

  1. Ask the user to enter their first name
  2. Ask the user to enter their last name
  3. Ask the user for their age on their next birthday
  4. Ask the user if they have used tobacco in the last 5 years. (Hint: Use a char variable and ask a yes/no question)
  5. 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)
  6. 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).
  7. 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. 
  8. 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).
  9. Ask the user if they are male or female. Male users will incur an additional 12.5% on top of the monthly premium.
  10. 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

  1. It’s good practice to initialize variables to default values that make sense (for example, set premium to 0.00)
  2. Include the <iomanip> header file. This will allow you to use various options to format your output such as setprecision
  3. 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