// C4_5.cpp : Defines the entry point for the console application. // while 迴圈應用 #include "stdafx.h" #include using namespace std; int main(int argc, char* argv[]) { double data = 0.0; // 變數宣告 double total = 0.0; double result = 0.0; int i = 0; char status = 'y'; cout << "1 公斤 = 2.20462 磅 "<< endl; while(status == 'y') // 鍵入 y 則迴圈繼續 { cout << endl << "請鍵入公斤值 : "; cin >> data; // 讀取一值 ++i; // 計數加一 result = data * 2.20462; cout << data << "公斤 =" << result << "磅" << endl; total += result; // 加總 cout << endl << "是否要查詢其他數值 (中J n 結束)? " ; cin >> status; // 讀取狀況字元 } cout << endl << "共輸入 " << i << "個值,且平均磅數為 : " << total/i << endl; return 0; }