Answer:
There are a few issues with your code.
In the declaration of fatcalories, you have written Declare Real fatcalories. However, Declare is not a valid keyword in any programming language that I'm aware of. You can simply declare a variable by writing its type and name, like Real fatcalories.
In the While loop that checks for a negative number of fat grams, you are using the variable fatgrams instead of fatGrams. Variable names are case-sensitive, so fatGrams and fatgrams are treated as two different variables. Make sure to use the correct variable name throughout your code.
In the calculatedSum module, you are using fat grams instead of fatGrams. Again, make sure to use the correct variable name.
In the calculatedSum module, you are setting the value of fatCalories to a boolean value (True or False) depending on whether the percentage of calories from fat is less than 0.3. However, fatCalories is a Real type variable, so you cannot assign a boolean value to it. Instead, you can use an If statement to display a message based on the value of fatCalories.
Here's how you can fix these issues and improve your code:
Module Main ()
Real fatGrams
Real calories
Real 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 calories
While calories > fatGrams * 9
Display "Error: the number of calories cannot be more than 9 times the fat grams"
Display "Please enter the correct number of calories"
Input calories
End while
Call calculatedSum
End Module
//Get the percentage
Module calculatedSum
Set fatCalories = (fatGrams * 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
Step-by-step explanation: