I need a help on this program it needs to calculate multiple number inputs using While Loop firstly and try the it with For Loop again.
#include <iostream>
using namespace std;
int main()
{
int numberOfItems;
int count;
int caloriesForItem;
int totalCalories;
cout <<"How many items did you eat? ";
cin >> numberOfItems;
cout <<endl;
cout <<"Enter the number of calories in each of the ";
cout << numberOfItems << " items eaten: " <<endl;
#include <iostream>
usingnamespace std;
int main()
{
int numberOfItems;
int count;
int caloriesForItem;
int totalCalories; //You need to initialize this
cout <<"How many items did you eat? ";
cin >> numberOfItems;
cout <<endl;
cout <<"Enter the number of calories in each of the ";
cout << numberOfItems << " items eaten: " <<endl;
cout << "Enter Calories for Items: ";
cin >> (caloriesForItem, count); //You set caloriesForItem and count in a funny manner here
while (caloriesForItem <= 0) //You have a while loop but you'll never exit it.
totalCalories = caloriesForItem * numberOfItems;
cout <<"Total calories eaten today = " << totalCalories <<endl;
cout<<endl;
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int numberOfItems;
int count;
int caloriesForItem;
int totalCalories = 0; //You need to initialize totalCalories
cout <<"How many items did you eat? ";
cin >> numberOfItems;
cout <<endl;
cout <<"Enter the number of calories in each of the ";
cout << numberOfItems << " items eaten: " <<endl;
cout << "Enter Calories for Items: ";
for (count = 0; count < numberOfItems; count++)
{
cin >> caloriesForItem; //We need to cin with a loop.
totalCalories += caloriesForItem; //Add the calories to the total calories.
}
cout <<"Total calories eaten today = " << totalCalories <<endl;
cout<<endl;
return 0;
}