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

C Programming #include <stdio.h> ONLY PLEASE Write a program that asks the user

ID: 3883734 • Letter: C

Question

C Programming

#include <stdio.h> ONLY PLEASE

Write a program that asks the user 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. 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 either of these happen, display an error message and end the program.

sample output:

1 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 / total calories

Explanation / Answer

Hi Please find the Below code :

#include <stdio.h>
int main()
{
float Calories;
float percentage;
  
float Fat;
printf("Enter the fat in grams:");
scanf("%d", &Fat);
  
Calories = Fat * 9;
percentage = Fat/Calories;

printf(" Percentage : %f", percentage);

if(percentage<30)
{
printf(" The Food is low in Fat");
}

else
{
printf("Error");
}


return 0;
}