利用 switch 判斷式,完成如下之練習:
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- int option;
- cout<<"請輸入您要買的飲料(1.咖啡 2.牛奶 3.紅茶): ";
- cin>>option;
- switch(option)
- {
- case 1:
- cout<<"您點的是咖啡"<<endl;
- break;
- case 2:
- cout<<"您點的是牛奶"<<endl;
- break;
- case 3:
- cout<<"您點的是紅茶"<<endl;
- break;
- default:
- cout<<"輸入錯誤"<<endl;
- }
- cout<<endl;
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |