Write a program that asks the user to enter the number of calories and fat grams in a food item. The program should display the percentage of the calories that come from fat. One gram of fat has 9 calories, so:
(Calories from fat) = (fat grams) * 9
The percentage of calories from fat can be calculated as:
(Calories from fat) / (total calories)
Extend as follow
1. The user first enters from a menu whether it is breakfast (B or b), lunch (L or l) or dinner (D or d). Use character and process by a switch.
2. The threshold for low calorie is different, for breakfast 10%, lunch 20%, dinner 30% (this value has to be assigned to some threshold variable in the above switch).
3. Include validation of menu choice.
4. In case any validation fails, display detailed error and exit the program by calling return 1 or return EXIT_FAILURE
5. Display the % from fat with one decimal digit.
Example 1:
What you have to eat:
B - breakfast
L - lunch
D - dinner
What you have: C
Error: C is not a valid menu choice
Example 2:
What you have to eat:
B - breakfast
L - lunch
D - dinner
What you have: L
How many calories: 600
How many grams of fat: 10
Your food has 15.0% calories from fat
It is a low calories food
Process the menu in a switch, setting the threshold as either 10, 20, or 30%. The rest of the program will be the same regardless what was the menu choice.
Incremental development: first do the textbook problem without input validation, then extend with validation, then extend for the additional parts.
sound like to me you need to study varibles a little before you start or check out some youtube videos on assigning variables/arethmetic. each option you have is going to need variable but you must declare the variable first.
The tutorial on this site is good (with occasional help from google) until you get to arrays, then you will go cross-eyed. People here will help you debug but don't expect us to do your homework for you.