@salem c ,I understand what you getting at with the for loop.
I have to do both for and while loop , they both are done , i just needed to know how to calculate the totals on the total calories, i'll use your above message, thank you!
p.s. Im new at this , so just bare with me :P
I got the code and then within the //My Code blocks , i was needed to write a loop for the total of items enter and then to have the sum of the total calories for each item
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
using namespace std;
int main()
{
int numberOfItems;
int count; //loop counter for the loop
int caloriesForItem;
int totalCalories;
cout << "How many items did you eat today? ";
cin >> numberOfItems;
cout << "Enter the number of calories in each of the "
<< numberOfItems << " items eaten: " << endl;
//My Code
int i = 1;
while (i <= numberOfItems)
{
cout << "Total calories for item " << i << " : "; i++;
cin >> caloriesForItem;
totalCalories += caloriesForItem;
}
//My Code
cout << "Total calories eaten today = " << totalCalories;
return 0;
}
| |
so i changed it to this, its working but only 1 problem.
I have to input 7 items , it works
then
items are
120
60
150
600
1200
300
200
I enter them and get the value of 2630.
but im requested to have 2631? Its their error right?