Answered step by step
Verified Expert Solution
Link Copied!

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 0.
Ensure that the number of calories entered isnt greater than fat grams \times 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 \times 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 formula are less than 0.3, 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 <0
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 <0
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 *9/ totalCalories
//determine if low fat
IF percentageFat <0.3 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions