📜  c++ 卡路里计算器使用 for 循环 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:51.016000             🧑  作者: Mango

代码示例1
#include 

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;
}