- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
-
-
- int option;
- cout<<"請輸入您要買的飲料(1.咖啡 2.牛奶 3.紅茶): ";
- cin>>option;
-
- //switch-case判斷選項
- switch(option){ //(要判斷的變數)
- //case1
- case 1:
- cout<<"咖啡"<<endl;
- break;
- //case2
- case 2:
- cout<<"牛奶"<<endl;
-
- //第三個case
- case 3:
- cout<<"紅茶"<<endl;
- break;
- default:
- cout<<"輸入錯誤"<<endl;
- }
-
- system("pause");
- return 0;
- }
複製代碼 |