Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You ll create both pseudocode and a flowchart to design a program that asks for fat grams and calories in a food item. Validate the
Youll create both pseudocode and a flowchart to design a program that asks for fat grams and calories in a food item.
Validate the input as follows:
Make sure the numbers of fat grams and calories arent less than
Ensure that the number of calories entered isnt greater than fat grams times
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 times : calories
Some nutritionists classify a food as low fat if less than percent of its calories come from fat. If the results of this formula are less than the program should display a message indicating the food is low in fat.
Is this correct?
START
Module Main
declare variables
DECLARE Real gramsOfFat
DECLARE totalCalories
DECLARE Real percentageFat
CALL caloriesFromFat
END Module
The gramsOfFat module get grams of fat
Module gramsOfFat
get grams of fat
DISPLAY "Enter # of total grams of fat."
INPUT gramsOfFat
validate
WHILE gramsOfFat
DISPLAY "Grams of fat cannot be less than zero."
INPUT gramsOfFat
End While
End Module
The totalCalories module gets total calories
Module totalCalories
get totalCalories
DISPLAY "Enter # of total calories."
INPUT totalCalories
validate
WHILE totalCalories
DISPLAY "Total calories cannot be less than zero."
End While
CALL caloriesFromFat
End Module
The percentageFat module shows the total percentage of calories from fat.
Module percentageFat
calculate percentage of calories from fat
SET percentageFat gramsOfFat totalCalories
determine if low fat
IF percentageFat THEN
DISPLAY "This food is low in fat."
End If
End Module
EXIT
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started