Description
The purpose of this challenge is to use the IF and NESTED-IF statements to control program flow.
Requirements
- Declare a string variable called contents
- Declare an int variable called length
- Declare a char variable called fractional
- Show a message asking the user “What type of data do you want to store (text or numeric)?”
- 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
- If the user enters the word text,
- Ask the user “How many characters will you need to store?”
- Using the cin command, receive the user’s input in the length variable
- If the user enters a negative value for length, show a message “There are no character data types that can hold a negative length”
- If the user enters a value of zero for length, show a message “You must use a string type”
- If the user enters a value of 1 for length, show a message “You can use either a string or a char type”
- If the user enters a value greater than 1 for length, show a message “You should definitely use a string type”
- If the user enters the word numeric
- Ask the user “Will you need to store fractional values (y/n)?”
- Using the cin command, receive the user’s input in the fractional variable
- If the user responds with a y, show a message “You can use a float or a double type”
- 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