標題:
switch 判斷式 (三)
[打印本頁]
作者:
tonyh
時間:
2016-10-15 14:49
標題:
switch 判斷式 (三)
本帖最後由 tonyh 於 2019-8-14 18:12 編輯
將題目的答案選項改為以ABCD表示,使用者輸入大寫或小寫都要能接受。
作者:
黃宥鈞
時間:
2016-10-15 15:20
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char ans;
cout<<"brainless question"<<endl;
cout<<"999+1=?,(a)10(b)10000(c)1000"<<endl;
cout<<"answer:"<<endl;
cin>>ans;
switch(ans)
{
case 'a':
case 'A':
cout<<"你腦殘嗎"<<endl;
break;
case 'b':
case 'B':
cout<<"你智障嗎"<<endl;
break;
case 'c':
case 'C':
cout<<"正確!"<<endl;
break;
default:
cout<<"輸入錯誤!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
許紘誌
時間:
2016-10-15 15:21
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
char ans;
cout<<"會生氣的問題:";
cout<<"請問你頭上有幾根頭髮?";
cout<<"請作答 (a)1根 (b)2根 (c)3根 (d)4根"<<endl;
cin>>ans;
switch(ans)
{
case 'a':
case 'A':
cout<<"你只有一根頭髮喔!可憐喔!要光頭了"<<endl;
break;
case 'b':
case 'B':
cout<<"你只有兩根頭髮喔!可憐喔!要光頭了"<<endl;
break;
case 'c':
case 'C':
cout<<"你只有三根頭髮喔!可憐喔!要光頭了"<<endl;
break;
case 'd':
case 'D':
cout<<"你只有四根頭髮喔!可憐喔!要光頭了"<<endl;
break;
default:
cout<<"我就是要讓你只有一點點頭髮的選項,打我啊!"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
曾彥翔
時間:
2016-10-15 15:23
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char a;
cout<<"----question----"<<endl;
cout<<"下列何者動物在椰子樹上摘香蕉的速度最快?"<<endl;
cout<<"(a)鬣狗(b)猴子(c)熊(d)狼"<<endl;
cin>>a;
switch(a)
{
case 'a':
cout<<"椰子樹上沒有香蕉!"<<endl;
break;
case 'A':
cout<<"椰子樹上沒有香蕉!"<<endl;
break;
case 'b':
cout<<"椰子樹上沒有香蕉!"<<endl;
break;
case 'B':
cout<<"椰子樹上沒有香蕉!"<<endl;
break;
case 'c':
cout<<"椰子樹上沒有香蕉!"<<endl;
break;
case 'C':
cout<<"椰子樹上沒有香蕉!!"<<endl;
break;
case 'd':
cout<<"椰子樹上沒有香蕉!"<<endl;
break;
case 'D':
cout<<"椰子樹上沒有香蕉!"<<endl;
break;
default:
cout<<"error!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
蕭澧邦
時間:
2016-10-15 15:25
#include<iostream>
#include<cstdlib>
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<<"答錯了!"<<endl;
break;
case 'a':
case 'A'
cout<<"答錯了!"<<endl;
break;
case 'c':
case 'C':
cout<<"答錯了!"<<endl;
break;
case 'd':
case 'D':
cout<<"答對了!"<<endl;
break;
default:
cout<<"輸入錯誤"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
吳晉榕
時間:
2016-10-15 15:27
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char ans;
cout<<"question"<<endl;
cout<<"烏龜有幾隻腳,(a)1(b)2(c)3(d)4"<<endl;
cout<<"answer:"<<endl;
cin>>ans;
switch(ans)
{
case 'a':
case 'A':
cout<<"答錯"<<endl;
break;
case 'b':
case 'B':
cout<<"答錯"<<endl;
break;
case 'c':
case 'C':
cout<<"答錯"<<endl;
case 'd':
case 'D':
cout<<"答對"<<endl;
break;
default:
cout<<"輸入錯誤!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
蔡幸融
時間:
2016-10-15 15:28
#include<iostream>
#include<cstdlib>
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<<"錯!"<<endl;
break;
case 'b':
case 'B':
cout<<"錯!"<<endl;
break;
case 'c':
case 'C':
cout<<"錯!"<<endl;
break;
case 'd':
case 'D':
cout<<"對!"<<endl;
break;
default:
cout<<"輸入錯誤!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
譚暐霖
時間:
2016-10-20 20:33
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char ans;
re:
cout<<"Brainless Question"<<endl;
cout<<"1+1=? "<<endl;
cout<<"Answer (a) 1 (b) 2 (c) 3 (d) 6 "<<endl;
cin>>ans;
switch (ans)
{
case 'a':
cout<<"wrong!"<<endl;
break;
case 'b':
cout<<"Correct!"<<endl;
break;
case 'c':
cout<<"wrong!"<<endl;
break;
case 'd':
cout<<"wrong!"<<endl;
break;
default:
cout<<"Eeror"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2