//---------------------------------------------------------------------------
#include <iostream>
//---------------------------------------------------------------------------
int total; // 全部的組合
int current; // 使用者現在輸入的數值
int counter; // 迴圈計數器
int main(int argc, char* argv[])
{
total = 0;
for (counter = 0;counter < 5; counter++) {
std::cout << "Number? ";
std::cin >> current;
total += current;
}
std::cout << "The grand total is " << total << '\n';
std::system("pause");
return 0;
}
//---------------------------------------------------------------------------
題目來源:C++風格與藝術 第二版 Steve Oualline 著 黃吉霈 編譯