Flow Control 1F

Description

The purpose of this challenge is to use the IF and NESTED-IF statements to control program flow.

Requirements

  1. Declare a string variable called contents
  2. Declare an int variable called length
  3. Declare a char variable called fractional
  4. Show a message asking the user “What type of data do you want to store (text or numeric)?”
  5. Using the cin command, receive input from the user who must type in the word text or numeric. Store the user’s response into contents
  6. If the user enters the word text,
    1. Ask the user “How many characters will you need to store?”
    2. Using the cin command, receive the user’s input in the length variable
    3. If the user enters a negative value for length, show a message “There are no character data types that can hold a negative length”
    4. If the user enters a value of zero for length, show a message “You must use a string type”
    5. If the user enters a value of 1 for length, show a message “You can use either a string or a char type”
    6. If the user enters a value greater than 1 for length, show a message “You should definitely use a string type”
  7. If the user enters the word numeric
    1. Ask the user “Will you need to store fractional values (y/n)?”
    2. Using the cin command, receive the user’s input in the fractional variable
    3. If the user responds with a y, show a message “You can use a float or a double type”
    4. If the user responds with an n, show a message “You should use an int type”

Sample Interaction / Output

What type of data do you want to store (text or numeric)? text
How many characters will you need to store? -1
There are no character data types that can hold a negative length

RUN IT AGAIN:

What type of data do you want to store (text or numeric)? text 
How many characters will you need to store? 0 
You must use a string type

RUN IT AGAIN:

What type of data do you want to store (text or numeric)? text 
How many characters will you need to store? 1 
You can use either a string or a char type

RUN IT AGAIN:

What type of data do you want to store (text or numeric)? text 
How many characters will you need to store? 100 
You should definitely use a string type

RUN IT AGAIN:

What type of data do you want to store (text or numeric)? numeric
Will you need to store fractional values (y/n)? y
You can use a float or a double type

RUN IT AGAIN:

What type of data do you want to store (text or numeric)? numeric
Will you need to store fractional values (y/n)? n
You should use an int type

LEGEND
PROGRAM OUTPUT
USER ENTRY
FROM INPUT

CATALOG ID: CPP-FLOW0001F

Print Requirements