Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ calorie calculator using a for loop

#include <iostream>

using namespace std;

int main()
{
    int numberOfItems;
    int totalCalories = 0;
    int caloriesForItem;
    cout << "How many items did you eat today? ";
    cin >> numberOfItems;
    cout << "Enter the number of calories in each of the "
         << numberOfItems << " items eaten:  " << endl;

    for (int count = 1; count <= numberOfItems; count++)
    {
        cout << "Enter calorie: ";
        cin >> caloriesForItem;
        totalCalories += caloriesForItem;
    }

    cout << "Total calories eaten today = " << totalCalories;

    return 0;
}
 
PREVIOUS NEXT
Tagged: #calorie #calculator #loop
ADD COMMENT
Topic
Name
9+6 =