Saturday
August 23, 2014

Homework Help: Fat gram calculator

Posted by John on Sunday, October 13, 2013 at 7:45pm.

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?

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

Computer programming - Submit pseudocode for the following programming exercise...
Programming - Submit pseudocode and a flowchart for the following programming ...
Programming and Design - Draw the hierarchy chart and design the logic for a ...
Programming in c++ - Write a program in c++ that inputs a number [1-12] from the...
computer programming - Design a program that asks the user to enter a nonegative...
MCC - Design a modular program that asks the user to enter the replacement cost ...
Programming - Write a pseudocode program that asks the user for an integer ...
logic and programing langage - Design a modular program that asks the user to ...
Program Logic Design - create a flowchart that shows the logic for a program ...
devry - A small startup software developer company needs to create a program ...

Search
Members