67 224
Assignments Done
99,2%
Successfully Done
In November 2018

Answer to Question #6780 in C++ for Muammar Mubin

Question #6780
Write a program to ask the user “How many items did you eat today”, and for each item ask the user also “how number of calories in each item” and then calculate the total_calories for each item in one variable then show the result , all that using for loop.
Expert's answer
C++:
Write a program to ask the user “How many items did you eat today”, and for each item ask the user also& “how number of calories in each item” and then calculate the total_calories for each item in one variable then show the result , all that using for loop.

#include <iostream.h>
&
int i,n;
float total_calories=0, calories;

void main()
{
cout<<"How many items did you eat today?";
cin>>n;
for (i=1;i<=n;i++){
& cout<<"Enter the item "<<i<<" number of calories:";
& cin>>calories;
& total_calories = total_calories + calories;
}
cout<<"Total calories: "<<total_calories<<"\n";
}

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