68 682
Assignments Done
99,6%
Successfully Done
In January 2019

# Answer to Question #48695 in C++ for ama

Question #48695
- The manager wants a program that allow her to enter the number ofcalories and grams of fat contained in a specific food. The program should calculate and display two values: the food's fat calories and its fat percentage. The f calories are the number of calories attributed to fat and are calculated by multiplying the food's fat grams by the number 9; this is because each gram of fat contains nine calories. The fat percentage is the ratio of the food's fat calories to its total calories. You calculate the fat percentage by dividing the food's fat calories by its total calories and then multiplying the result by 100. The fat percentage should be displayed with zero decimal places. the program should display an appropriate error message if either or both input values are less than 0.
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <cstdlib>
using namespace std;
int main()
{
int calories;
int fatGrams;
int foodsFatCalories;
float fatPercentage;
do
{
system("cls");
cout<<"Enter the calories : ";
cin>>calories;
if (calories < 0 )
{
system("cls");
cout<<"Error!!Wrong input!!"<<endl;
system("pause");
}
} while (calories < 0);
do
{
system("cls");
cout<<"Enter the grams of fat : ";
cin>>fatGrams;
if (fatGrams < 0 )
{
system("cls");
cout<<"Error!!Wrong input!!"<<endl;
system("pause");
}
} while (fatGrams < 0);
foodsFatCalories = float(fatGrams * 9);
fatPercentage =  float( foodsFatCalories / float(calories + foodsFatCalories) * 100 );
cout<<"------------------------------------------------------"<<endl;
cout<<"Calories            : "<<calories<<endl;
cout<<"Grams of fat        : "<<fatGrams<<endl;
cout<<"Food's fat calories : "<<foodsFatCalories<<endl;
cout<<"Fat percentage      : "<<int( fatPercentage + 0.5)<<endl;
cout<<"------------------------------------------------------"<<endl;
system("pause");
return 0;
}
﻿

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!