Needs to be done in C++ Write a program that asks for the number of calories and
ID: 3805732 • Letter: N
Question
Needs to be done in C++ Write a program that asks for the number of calories and fat grams in a food. The program should display the percentage of calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating that the food is low in fat. One gram of fat has 9 calories, so Calories from fat = fat grams * 9 The percentage of calories from fat can be calculated as Calories from fat divide by total calories Input Make sure the number of calories and fat grams are not less than 0. Also, the number of calories from fat cannot be greater than the total number of calories. If that happens, display an error message indicating that either the calories or fat grams were incorrectly entered.Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
/* variable declaration*/
int NumOfCalory, FatGramAmt, CaloryFrmFat,CalPrcnt;
/* to read the input from user*/
cout << "Enter the total no. of calories and the fat grams in food.Please make sure the values should be greater than Zero ";
cin >> NumOfCalory >> FatGramAmt;
/* calcultation of calories from fat */
CaloryFrmFat = FatGramAmt *9;
/* If clause to check the Calories from fat is less than the total calories
if (CaloryFrmFat > NumOfCalory)
{
cout << "Either the no. of calories and the fat grams are entered incorrectly " << endl;
}/* If the above if clause fails then calculating the percentage of calorie from fat.*/
else
{
CalPrcnt = (CaloryFrmFat * 100 / NumOfCalory);
if (CalPrcnt < 30)
cout << "Your Food is with low fat" << endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.