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. 👍
  2. 👎
  3. 👁
  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

    1. 👍
    2. 👎
  2. my while loop will not work for this, it is, while fatGrams < 0 or calories < 0 or calories > fatGrams * 9

    1. 👍
    2. 👎
  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.

    1. 👍
    2. 👎
  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?

    1. 👍
    2. 👎
  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.

    1. 👍
    2. 👎

Respond to this Question

First Name

Your Response

Similar Questions

  1. Health--Check my answers

    1. The best way to describe fitness is: being slim and low in body fat being big, strong, and “buffed” being flexible and having a sense of overall well-being *** all of the above 2. The best way to describe wellness is:

  2. CIS

    Draw a flowchart or write pseudocode to represent the logic of a program that allows the user to enter a value. The program multiplies the value by 10 and outputs the result.

  3. Heallth Help NOW

    which type of fat is not naturally found in foods and should be very used very little in your diet? A. monounsaturated fat B. Saturated fat C. trans fat D. unsaturated fat my answer is B is it correct.

  4. 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

  1. 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

  2. math

    a 14- gram serving of mayonnaise contains 11 grams of fat. what percen tof the mayonnaise, to the nearest tenth of a percent, is fat?

  3. Computer Literary

    Which of the following is Not an example of debugging A)Looking for errors in programming code B)Fixing misspelled commands in programming code C)Solving faulty logic in programming code D)Upgrading to improve the programming code

  4. Programming and Design

    Draw the hierarchy chart and design the logic for a program that calculates the projected cost of an automobile trip. Assume that the user's car travels 20 miles per gallon of gas. Design a program that prompts the user for a

  1. 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

  2. statistics

    sing the proper average, find the average number of grams of fat per ounce of meat or fish that a person would consume over a 5-day period if he ate these: 3 oz fried shrimp 3.33 g/oz of fat 3 oz veal cutlet 3.00 g/oz of fat 2 oz

  3. computer programming

    Design the pseudocode for a program that allows a user to enter 10 numbers, then displays them in the reverse order of their entry

  4. Programming in Python

    A customer in a store is purchasing five items. Design a program in python that asks for the price of each item, and then displays the subtotal of the sale, the amount of the sales tax , and the total. Assume the sales tax is 6

You can view more similar questions or ask a new question.