Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The manager of Willow Springs Health Club wants a program that allows her to ent

ID: 3666000 • Letter: T

Question

The manager of Willow Springs Health Club wants a program that allows her to enter the number of calories and grams of fat contained in a specific food. The ptogram should calculate and display two values: the food's fat calories and its fat percentage. The fat 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 and then by multiplying the result by 100. The fat percentage should be displayed with zero decimal places. Create a Visual Basic Window application.

Explanation / Answer

#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;
}