Coding problem! please check my work!
test information:

Validate the input as follows:

Make sure the numbers of fat grams and calories aren’t less than 0.
Ensure that the number of calories entered isn’t 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
my coding: (note this is a false code for a test, NOT a real code!)
// start

Module Main ()


Declare Real fatGrams
Declare Real totalCalories
Declare Boolean fatCalories

//Get the number of fat grams
Display "Enter the number of fat grams."
Input fatGrams

While fatGrams < 0
Display "Error: the number of fat grams cannot be less than 0"
Display "Please enter the correct number of fat grams"
Input fatGrams
End while

//Get the number of calories
Display "Enter calories"
Input totalCalories

While totalCalories < 0
Display "Error: the number of calories cannot be less than 0"
Display"Please enter the correct number of calories"
Input totalCalories
End while


//Make sure the Calories isnt greater than 9 times the fat grams
While totalCalories > fatGrams*9
Display "Error: the number cannot be more than 9 times the fat grams"
Display "Please enter the correct number of calories"
Input totalCalories
End while


Call calculatedSum
End Module

//Get the percentage
Module calculatedSum
Set fatCalories=(fat grams*9) / calories
If fatcalories < 0.3 Then
Display "This food is low in fat"
Else
Display "this food is not low in fat"
End if

End Module

Q&A Education