1. Engineering
  2. Computer Science
  3. write a program in c that prompts a user to...

Question: write a program in c that prompts a user to...

Question details

Write a program in C that prompts a user to select any five beverages of your choice (e.g Coke, Lemon
Tea, etc.). User should be able to select one of these options using only integers from 0 to 4 as inputs.
Once a user has made the choice, print the chosen drink along with its calorie information. You may look
up the calorie information online.
Example input: 3
Example output:
Selected drink: Coca Cola
Calorie count: 140 Calories
Notes:
 You can assume that the user will input integers. You do not need to handle invalid inputs of other
types (such as strings, floats, etc.).
 Your program should gracefully terminate if a user enters wrong input three times. In addition, after
every invalid attempt, your program should tell the user how many tries he/she has remaining. For
example, the prompt should work something like this:
o Prompt 1: User enters 6. Your program should tell that input is invalid and enter again. Also print
the remaining tries (2).
o Prompt 2: User enters -1. Your program should tell that input is invalid and enter again. Also print
the remaining tries (1).
o Prompt 3: User enters 200. Your program should tell that input is invalid and terminate. Also print
the remaining tries (0).
o If the user enters a correct input on or before the last try, the program should behave normally,
and output should be like the provided example.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution