60 627
Assignments Done
97,8%
Successfully Done
In April 2018

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.
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions