Description
The purpose of this challenge is to use any IF structures (decide between independent IF blocks, IF-ELSE, NESTED IF-ELSE, IF-ELSE-IF) and the DO-WHILE statements while using basic comparison operators.
Requirements
- Create a constant int called TARGET, set to 100
- Create an integer called total. This will be used as an accumulator.
- Create an integer called input
- Use a do-while loop that continues as long as total is less than TARGET
- Within the do-while, ask the user to enter a value. Use the input variable for the user’s value
- Accumulate input in total. Display the value of total (See Sample Interaction)
- Within the do-while, display the following messages as described below
- if total is less than 5, show “Long way to go!”
- if total is less than 20, show “Keep going!”
- if total is less than 50, show “More!”
- if total is equal to 50, show “Halfway there!”
- if total is less than or equal to 90, show “Go go go!”
- if total is greater than 90, show “Home stretch!”
- if total is 98 or more, show “Sooo close!”
- After the do-while, show “Success!”
Sample Interaction / Output
Enter a number: 1 We're at 1 Long way to go Enter a number: 3 We're at 4 Long way to go Enter a number: 14 We're at 18 Keep going! Enter a number: 5 We're at 23 More! Enter a number: 10 We're at 33 More! Enter a number: 10 We're at 43 More! Enter a number: 7 We're at 50 Halfway there! Enter a number: 11 We're at 61 Go go go! Enter a number: 20 We're at 81 Go go go! Enter a number: 15 We're at 96 Home stretch! Enter a number: 3 We're at 99 Sooo close! Enter a number: 9 We're at 108 Success!
LEGEND
PROGRAM OUTPUT
USER ENTRY
FROM INPUT
CATALOG ID: CPP-LOOP0003b
Print Requirements