Respuesta :
Answer:
#include <iostream>
using namespace std;
int main()
{
double calories, fat_grams, fat_calories;
double percentage_of_calories;
cout << "Enter the number of calories in a food: ";
cin >> calories;
cout << "Enter the number of fat grams in a food: ";
cin >> fat_grams;
if(calories >= 0 && fat_grams >= 0){
fat_calories = fat_grams * 9;
percentage_of_calories = (fat_calories / calories) * 100;
if(fat_calories > calories) {
cout << "Error in input" << endl;
} else {
cout << percentage_of_calories << "%" << " fat" << endl;
}
if(percentage_of_calories < 0.30)
cout << "Low in fat." << endl;
} else {
cout << "Error in input" << endl;
}
return 0;
}
Explanation:
- Declare variables
- Ask user to input calories and fat grams
- Check if calories and fat grams are greater than zero. If they are, calculate the fat calories and percentage of calories. Then, check if calories from fat is smaller than the total calories of the food. If it is, print the percentage. Also, check if the percentage is smaller than 30%.