Asked by junaid masood
Write a program that asks for the number of calories and fat grams in a food. The program should display the percentage
of 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
Input validation: Make sure the number of calories and fat grams are not less than 0.
Also, the number of calories from fat cannot be greater than the total number of calories. If that happens, display an
error message indicating that either the calories or fat grams were incorrectly entered.
of 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
Input validation: Make sure the number of calories and fat grams are not less than 0.
Also, the number of calories from fat cannot be greater than the total number of calories. If that happens, display an
error message indicating that either the calories or fat grams were incorrectly entered.
Answers
There are no human answers yet.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.