Question

Design a program that asks for the number of fat grams and calories in a food...

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 grams and calories is not less than 0.
According to nutritionist 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 nutritionist classify a food as "low fat" if less than 0.3, the program should display a message indicating the food is low in fat.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;

int main() {
  
   double fatGrams,calories,caloriesPer;
  
   do
   {
   cout<<"\nEnter the number of fat grams : ";
   cin>>fatGrams;
   if(fatGrams < 0)
   cout<<"\nFat grams should not be less than 0 . Enter again";
   }while(fatGrams < 0);
  
   do
   {
   cout<<"\nEnter the number of calories : ";
   cin>>calories;
   if(calories < 0)
   cout<<"\nCalories should not be less than 0 . Enter again";
   }while(calories < 0);
  
  
caloriesPer = (fatGrams*9)/calories;
cout<<"\nPercentage of calories from fat : "<<caloriesPer;

if(caloriesPer <0.3)
cout<<"\nFood is low in fat";

  
   return 0;
}

Output:

Enter the number of fat grams : -7
Fat grams should not be less than 0 . Enter again
Enter the number of fat grams : 6
Enter the number of calories : 100
Percentage of calories from fat : 0.54

Do ask if any doubt. Please up-vote.

Add a comment
Know the answer?
Add Answer to:
Design a program that asks for the number of fat grams and calories in a food...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Python program that asks the user to enter the number of calories and fat...

    Write a Python program that asks the user to enter the number of calories and fat grams in a food item. The program should display the percentage of the calories that come from fat. One gram of fat has 9 calories, therefore: Calories from fat = fat grams * 9 The percentage of calories from fat can be calculated as follows: Calories from fat / total calories If the calories from fat are less than 30 percent of the total...

  • In Python code: Write a program to calculate the percentage of fat calories in a food...

    In Python code: Write a program to calculate the percentage of fat calories in a food item. Your program should allow the total number of calories in the food item and the number of grams of fat. Validate the input as follows: - Make sure the number of calories and the number of fat grams are not less than 0. - There are 9 calories in every gram of fat. The calories from fat must not exceed the total calories...

  • L. Collect data from several fast food chains on the number of fat calories and grams of saturated fat in menu ite...

    L. Collect data from several fast food chains on the number of fat calories and grams of saturated fat in menu items. Record at least 12 ordered pairs of (fat calories, grams of saturated fat) Organize your data in a table. Il. Make a scatter plot of the data on graph paper. Be sure to label the axes and use an appropriate title for the graph. You may wish to use a graphing calculator, spread sheet, or other technology resource...

  • Listed are the calories and grams of saturated fat for a sample of ten food items. Find the following a. Mean calories...

    Listed are the calories and grams of saturated fat for a sample of ten food items. Find the following a. Mean calories b. Median calories c. Mean grams of saturated fat d. Median grams of saturated fat Grams of Food item Calories saturated fat Chocolate bar (1.45 ounces) Meat & veggie pizza (large slice) New England clam chowder (1 cup) 216 7.0 364 5.6 1.9 149 Baked chicken drumstick 75 0.6 (no skin, medium size) Curly fries, deep-fried (4 ounces)...

  • The predicted calories in food items based on grams of fat are represented by the residual...

    The predicted calories in food items based on grams of fat are represented by the residual plot. What does the pattern in the residual plot indicate about the type of model? The pattern is random, indicating a good fit for a nonlinear model. The pattern shows the points are far from the zero line, indicating a good fit for a linear model.  The pattern is random, indicating a good fit for a linear model.  The pattern shows the points are far from...

  • USING JAVA Write a program for calculating body fat and body fat percentage. The following simple...

    USING JAVA Write a program for calculating body fat and body fat percentage. The following simple formulas will be used for our calculations Body fat formula for female: A1 = (weight * .732) + 8.987 A2 = wrist measurement / 3.14 A3 = waist measurement * .157 A4 = hip measurement * .249 A5 = forearm measurement * .434 B = A1 + A2 - A3 – A4 + A5 Body fat = weight – B Body fat percentage =...

  • Write a program that asks the user to enter a number ofseconds.• There are...

    Starting Out with C++ (9th Edition)  Chapter 4, Problem 7PCWrite a program that asks the user to enter a number of seconds.• There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds.• There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater...

  • 1. Creatc a lava program thal asks the user to cnter his/her first name and last...

    1. Creatc a lava program thal asks the user to cnter his/her first name and last namc, in a single linc and separaled by a spacc. The program should output separately the first namc and the last name. (Use the Scanner class.) 2. Create a Java program thal asks the user for a medium (air, water or sleel), and outputs the speed of sound in thal medium (1 100 feclsec in air, 4900 feesec in water and 16,400 feet sec...

  • Students are asked to calculate the total fat and saturated fat content of 2 favorite packaged...

    Students are asked to calculate the total fat and saturated fat content of 2 favorite packaged fast food items.Using the calculation table below, you will estimate the total fat and saturated fat contents of each packaged food item. Some food labels already have the percentage calculation completed, which will eliminate the need for completing the calculation. Once you identify the fat content you will then identify what modifications might make the food healthier or an alternative food item that might...

  • Project 1, Program Design 1. Write a C program replace.c that asks the user to enter...

    Project 1, Program Design 1. Write a C program replace.c that asks the user to enter a three-digit integer and then replace each digit by the sum of that digit plus 6 modulus 10. If the integer entered is less than 100 or greater than 999, output an error message and abort the program. A sample input/output: Enter a three-digit number: 928 Output: 584 2. Write a C program convert.c that displays menus for converting length and calculates the result....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT