Write a c program that will ask the user how many items he has eaten today and he should ask the user to enter the calories for each of the item and then display the total calories consumed. Write this program using a while loop.
1
Expert's answer
2011-06-20T12:12:05-0400
#include <stdio.h> int main() { & int i,n; & float total_calories, calories; & & printf("Please enter how many items your have eaten today = "); & scanf("%d",&n); & & i=0; & total_calories=0; & while (i<n) & { & printf("Please enter calories for item %d: ", i+1); scanf("%g",&calories); total_calories+=calories; i++; & }; printf("The total calories is %g", total_calories);
Comments
Leave a comment