close

//---------------------------------------------------------------------------
#include <iostream>
//---------------------------------------------------------------------------
int total;    //目前數字的總和
int item;     //下一個加總的數字

int main(int argc, char* argv[])
{
        total = 0;
        while (true){
          std::cout << "請輸入欲加總的數字 \n";
          std::cout << " 或 0 表示結束: ";
          std::cin >> item;

          if (item == 0)
            break;

          total += item;
          std::cout << " 小計: " << total << '\n';
        }
        std::cout << " 總和: " << total << '\n';
        std::system("pause");
        return 0;
}
//---------------------------------------------------------------------------


 題目來源:C++風格與藝術 第二版 Steve Oualline 著 黃吉霈 編譯
arrow
arrow
    全站熱搜

    jumbowind 發表在 痞客邦 留言(0) 人氣()