標題:
switch 判斷式 (四)
[打印本頁]
作者:
鄭又綸
時間:
前天 17:50
標題:
switch 判斷式 (四)
將題目的答案選項改為以ABCD表示,使用者輸入大寫或小寫都要能接受。
參考回應
A or a: 用跳的嗎?
B or b: 沒吃過豬肉也看過豬走路!
C or c: 你是豬啊?
D or d: 答對了!
其他: 輸入錯誤!
#include<cstdlib>
#include<iostream>
using namespace std;
int main()
{
char ans; //宣告字元
cout<<"<小米的腦殘問答>"<<endl;
cout<<"請問豬有幾隻腳? (A)一隻 (B)兩隻 (C)三隻 (D)四隻"<<endl;
cout<<"請作答: ";
cin>>ans;
switch(ans)
{
case 'a':
case 'A':
cout<<"用跳的嗎?";
break;
case 'b':
case 'B':
cout<<"沒吃過豬肉也看過豬走路!";
break;
case 'c':
case 'C':
cout<<"你是豬啊!";
break;
case 'd':
case 'D':
cout<<"答對囉!";
break;
default:
cout<<"輸入錯誤!";
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
孫育崧
時間:
3 小時前
此帖僅作者可見
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2