Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a program psuedocode that asks for the number of fat grams and calories i

ID: 3560508 • Letter: D

Question

Design a program psuedocode that asks for the number of fat grams and calories in a food item. Validate the input as follows:

- Make sure the number of fat grams and calories are not less than 0.

- According to nutritional formulas, the number of calories cannot exceed fat grams x 9. Make sure that the number of calories entered is not greater than fat grams x 9.

Once correct data has been entered, the program should calculate and display the percentage of calories that come from fat. Use the following formula:

Percentage of calories from fat = (fat grams x 9) / calories


Some nutritionists classify a food as "low fat" if less than 30 percent of its calories come from fat. If the results of this forumlas are less than 0.3, the program should display a message indicating the food is low in fat.

Explanation / Answer

declare and initialize float fgrams, float calories, and float fpercentage
- input fgrams and calories
- if fgrams or calories > 0, print error and exit
- if calories > (fgrams * 9), print error and exit
- set fpercentage = fgrams * 9 / calories
- if fpercentage < 0.03, print "Low in fat, yay!"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote