# Computer programming

Submit pseudocode 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 number of fat grams and calories are not less than 0.

- According to nutritional formulas, the number of calories cannot exceed fat grams X 9. Make sure that the number of calories entered is not 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

Some nutritionists classify a food as low fat if less than 30 percent of its calories come from fat. If the results of this forumlas are less than 0.3, the program should display a message indicating the food is low in fat.

1. 0
1. I'll give you a headstart:

Input:
input fat_grams;
input calories;

Validate:
- Make sure the number of fat grams and calories are not less than 0.
- the number of calories cannot exceed fat grams X 9.

Calculations:
- Percentage of calories from fat = (fat grams x 9) / calories
- is it low-fat?

Output:
- Print input data
- print output information

posted by MathMate
2. my while loop will not work for this, it is, while fatGrams < 0 or calories < 0 or calories > fatGrams * 9

posted by Viper
3. typically one would code like this:

do{
print: instructions;
enter fatGrams;
enter calories;
}while(data unsatisfactory);

So that it would request data at least once.

posted by MathMate
4. Do
Display Error: "Error: The number of calories and fat grams cannot be less than 0. The number of calories cannot be greater than fat grams * 9."
Display "Enter the correct number of calories."
Input calories
Display "Enter the correct number of fat grams."
Input fatGrams
While fatGrams > 0 and calories > 0 and calories < fatGrams * 9

the while part was just a while loop i originally did and it worked

it would also work with a do-while loop like what i typed above?

posted by Viper
5. Basically, yes, it works.

From the user's point of view, it does not seem logical to see "Error,..." before he types in anything.

I would replace the "error" message with an insisting message, such as:

"Please enter non-negative values for ...., and ensure that ...< 9*..."

It would be nicer, of course, to insert a message indicating an error for the second time around, such as:

If (count greater than 1) Display "Sorry, there is an error in the input. Please follow the instructions carefully."

For this, you'll need a counter called count that was set to 1 before entering the loop, and incremented by 1 at the end of the loop.

posted by MathMate

## Similar Questions

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. ### Computer Programing & Logic Design

Submit pseudocode and a flowchart for the following programming exercise: Software Sales A software company sells a package that retails for \$99. Quantity discounts are given according to the following table: Quantity Discount
3. ### Computer Programing & Logic Design

Submit pseudocode and a flowchart for the following programming exercise: Test Average and Grade Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the
4. ### Computer Programing & Logic Design

Submit pseudocode and a flowchart for the following programming exercise: Largest and Smallest Design a program with a loop that lets the user enter a series of numbers. Theuser should enter -99 to signal the end of the series.
5. ### Computer Programing & Logic Design

Submit pseudocode and a flowchart for the following programming exercise: Largest and Smallest Design a program with a loop that lets the user enter a series of numbers. Theuser should enter -99 to signal the end of the series.
6. ### 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
7. ### programming

I am supposed to make a pseudocode for a fat gram calculator and I want to know if my code is correct. This is the instructions: Design a program that asks for the number of fat grams and calories in a food item. Validate the
8. ### programming

You have the final sales figures for the four quarters in 2010 for Bennets Used Auto Sales, and you are to design a program that asks for the sales figures, computes the total sales for the year, and calculates and displays the
9. ### computer science

Mr Ali has given a test to his class. He would like to have the average score for the class as well as the highest and lowest scores. Write a pseudocode to calculate and display these values. Then convert your pseudocode into a
10. ### 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

More Similar Questions