Answer to Question #195128 in C++ for Vina

Question #195128

The following incomplete program first asks the user to enter the number of items he/she has eaten today and then to enter the number of calories for each item. It then calculates the number of calories he/she has eaten for the day and displays the value. #include 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; // ------------- Your code -------------- cout << "Total calories eaten today = " << totalCalories; return 0; }.complete the code.complete use a for loop to read in the calories of all the items. Test your program by entering 7 for the number of items and the following values for the calories: 7 120 60 150 600 1200 300 200


1
Expert's answer
2021-05-18T17:28:39-0400
#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; // ------------- Your code --------------
    int a[numberOfItems],i,f=0;
    for(i=0;i<numberOfItems;i++)
    {
        cin>>a[i];
        f=f+a[i];
    }
    totalCalories=f;
    cout << "Total calories eaten today = " << totalCalories;
    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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog