# Fat gram calculator

Design a program that asks the user 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 * 9. Make sure that the number of calories entered is not greater than fat grams * 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 * 9) / Calories
Some nutritionists classify food as “ low fat” if less than 30percent 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.

how to write this in pseudo code for both Module and function?

------------------------------

method:
-------

Module main ( )

/ / Local variables
double fatGramCalculator(double fatGrams, double calories)

// If fat grams or calories are less than 0, display a message and return -1
if (fatGrams < 0 || calories < 0)

Display ('Number of fat grams and calories must be greater than 0

return -1;

// If calories is greater than fat grams * 90, display a message and return -1
if (calories > (fatGrams * 9)

Display('Calories must not exceed fat grams x 9

return -1;

// Calculate percentage of calories from fat
double caloriesFromFat = (fatGrams * 9) / calories;

// Display calories from fat, multiplying percentage by 100 to remove decimal point
Display('%d percent of calories from fat,
caloriesFromFat * 100);

// If less than 30% of calories come from fat, display a message
if (caloriesFromFat < 0.3)

Display('Food is low in fat

// Return the number of calories from fat
return caloriesFromFat;

End Module

Function Real sum ( Real fatGrams, Real doubleCalories )
Declare Real result
Set result = ( fatGrams*9 ) / calories
Return result
End Function

--------
is this right?

1. 👍
2. 👎
3. 👁

## Similar Questions

1. ### computer programming

Design the logic for a program that allows a user to enter any amount of numbers up to 10 or until a sentinal value of -1 is entered. Then the program displays the count of the numbers entered and numeric average of the numbers

2. ### Is My Pseudocode Correct? - Programming

I am supposed to make a pseudocode for a fat gram calculator. These are the instructions: Design a program that asks for the number of fat grams and calories in a food item. Validate the input as follows: - Make sure the number of

3. ### java programming

1. Time Calculator Write a program that asks the user to enter a number of seconds. • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the

4. ### Programing Logic and design

Design a program that asks the user to enter a store's sales for each day of the week. The amounts should be stored in an one dimensional array. use loop to calculate the total sales for the week and display the results. (In

1. ### Programming Logic and Design (help?)

Design a retirement planning calculator for Skulling Fincancial Services. Allo a user to enter a number of working years remaining in the user's career and the annual amount of money the user can save. Assume that the user earns

2. ### C++

// Program: name of program // Author: your name // Date Written: date you began writing the program /* Abstract: Brief description of the program */ Include in-line comments in the body of your program. You can convert

3. ### intro to computer programming

Write a program that asks the user to enter the number of packages purchased. The program should then display the amount of the discount (if any) and the total amount of the purchase after the discount. Your program should use a

4. ### math

A dietician is planning a snack package of fruit and nuts. Each ounce of fruit will supply zero units of​ protein, 3 units of​ carbohydrates, and 2 units of​ fat, and will contain 30 calories. Each ounce of nuts will supply

1. ### Programming

Submit pseudocode and a flowchart for the following programming exercise: Fat Gram Calculator Design a program that asks for the number of fat grams and calories in a food item. Validate the input as follows: - Make sure the

2. ### Java

Design a flowchart for a program that prompts the user to enter ten numbers one at a time. After the user has entered all ten number the program will then print out the total of those ten number and quit.

3. ### math

protein = 4 calories per gram carbohydrate = 4 calories per gram fat = 9 calories per gram A serving of chicken has 27 grams of protein and 3 grams of fat. How many calories are in a serving of chicken?

4. ### programming logic and design

I need help writing pseudocode for this problem: Design a retirement planning calculator for skulling financial services • Allow a user enter a number of working years remaining in the user career and the annual amount of money