Answer to Question #3165 in C++ for fmn

Question #3165
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);

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS