// C3_4.cpp : Defines the entry point for the console application. // goto 無條件分支指令 -- 單位轉換 #include "stdafx.h" #include using namespace std; int main(int argc, char* argv[]) { int data = 0; //宣告變數及設定初始值 int I = 0; double meters = 0; start: cout << endl << " @@@ 公尺與英制轉換! @@@" << endl << "選擇下列轉換單位 : " << endl << endl << "1 吋" << endl << "2 呎" << endl << "3 碼" << endl << "4 哩" << endl << "5 離開" << endl << endl << "請輸入公尺數 ? "; cin >> meters; cout << endl << "請輸入選擇 : "; cin >> data; cout << endl; if( data == 5 ) goto endp; // goto 敘述 switch(data) { case 1: cout << endl << meters << " 公尺 = " << meters * 39.37 << " 吋" << endl; break; case 2: cout << endl << meters << " 公尺 = " << meters * 3.28084 << " 呎" << endl; break; case 3: cout << endl << meters << " 公尺 = " << meters * 1.09361 << " 碼" << endl; break; case 4: cout << endl << meters << " 公尺 = " << meters * 0.00062 << " 哩" << endl; break; default: cout << endl <<"輸入數值錯誤, 請重新鍵入." << endl; } goto start; endp: return 0; // endp 標纖處 }