For my intro class I have to write a code that allows the user to input multiple integers. For example, I ask how many items that person has eaten that day (in this example lets just say 5 items), I then ask how many calories are in each item. So using 5 items in this example, how would I allow the user to input 5 different amounts of calories. Just made this account and am still getting the hang of using this website, sorry if this question has been asked before.
This is what I have so far and It's outputting the correct answer. If I eat 5 items and those
5 items have 200, 300, 560, 45, and 129 calories the sum of them should be 1234 calories.
All I get is 129 calories.
Let me know what you think of the program that I made for you. In regards to your program, the "int sum=sum+caloriesPar;" this is after you 0 sum out first.
#include <iostream>
usingnamespace std;
int main()
{
int Calorie, Counter=-10, Totalfat=0;
cout<<"*********How fat are you??********"<<endl<<"Please enter the number of meals you've eaten today..."<<endl;
while (Counter<0 or Counter>10)
{
cin>>Counter;
}
cout<<"Please enter the number of calories you ate for each meal..."<<endl;
for(int A=Counter; A>0; A--)
{
cout<<"meal "<<((Counter-A)+1)<<" :";
cin>>Calorie;
cout<<endl;
Totalfat=Totalfat+Calorie;
}
cout<<"Over "<<Counter<<" Meals, you've' consumed "<<Totalfat<<" Calories"<<endl;
if (Totalfat>1500)
{
cout<<"You really need to get off this program, start working out and eating healthy!!!!!!!!!!"<<endl<<"************************YOU FAT*********************";
}
}