利用switch敘述, 設計一有趣的急智問答.- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int answer;
- cout<<"***小米的腦殘問答***"<<endl;
- cout<<"請問豬有幾隻腳? (1)一隻 (2)兩隻 (3)三隻 (4)四隻"<<endl;
- cout<<"請作答: ";
- cin>>answer;
- switch(answer)
- {
- case 1:
- cout<<"用跳的啊?"<<endl;
- break;
- case 2:
- cout<<"沒吃過豬也看過豬走路!"<<endl;
- break;
- case 3:
- cout<<"你是豬啊! 笨!"<<endl;
- break;
- case 4:
- cout<<"答對了!"<<endl;
- break;
- default:
- cout<<"輸入錯誤!"<<endl;
- }
- system("pause");
- return 0;
- }
複製代碼 |