標題:
[作業] switch 與 if...else if...else
[打印本頁]
作者:
tonyh
時間:
2013-10-19 17:58
標題:
[作業] switch 與 if...else if...else
運用 if...else if...else 語法改寫, 今天課堂上用 switch 判斷式寫的選擇題.
作者:
張郁偵
時間:
2013-10-19 18:10
#include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{
int answer;
cout<<" 一, 選擇題"<<endl;
cout<<"請問豬的運動型態為何? (1)飛(2)爬(3)走(4)以上全部正確"<<endl;
cin >>answer;
{
if (answer==1)
cout << "你有看過豬長翅膀的嗎?"<<endl;
else if (answer==2)
cout<<"豬不是昆蟲!"<<endl;
else if (answer==3)
cout<<"賓果!!"<<endl;
else if (answer==4)
cout<<"瞎!"<<endl;
else
cout<<"輸入錯誤"<<endl;
}
system ("pause");
return 0;
}
複製代碼
作者:
周雍程
時間:
2013-10-19 18:12
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int answer;
cout <<"<???>"<<endl;
cout <<"你晚上吃什麼? (1)垃圾 (2)鋼鐵 (3)我 (4)沒有吃東西"<<endl;
cout <<"請作答:";
cin >> answer;
if(answer == 1)
{
cout<<"你是流浪漢嗎"<<endl;
}
else if(answer == 2)
{
cout <<"嗨!鋼鐵人"<<endl;
}
else if(answer == 3)
{
cout <<"回家吃自己!"<<endl;
}
else if(answer == 4)
{
cout <<"你失憶了,走!去看醫生"<<endl;
}
else
{
cout <<"不會數數嗎,只有4個而已!!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
張彥承
時間:
2013-10-19 18:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int answer;
cout<<"<Smosh's stupid question>"<<endl;
cout<<"2個半小時是幾分鐘
1)120分(2)60分(3)55分(4)59分"<< endl;
cout<<"
lease answer:"<<endl;
cin>>answer;
if(answer==1)
{
cout<<"wrong answer!"<<endl;
}if(answer==2)
{
cout<<"Bingo!"<<endl;
}if(answer==3)
{
cout<<"wrong answer!"<<endl;
}if(answer==4)
{
cout<<"wrong answer!"<<endl;
}else
{
cout<<"you really are a dickhole!"<<endl;
}
system("pause");
return 0;
}
作者:
張彥承
時間:
2013-10-19 18:13
本帖最後由 張彥承 於 2013-10-26 16:35 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int answer;
cout<<"<Smosh's stupid question>"<<endl;
cout<<"2個半小時是幾分鐘:(1)120分(2)60分(3)55分(4)59分"<< endl;
cout<<"Please answer:"<<endl;
cin>>answer;
if(answer==1)
{
cout<<"wrong answer!"<<endl;
} else if(answer==2)
{
cout<<"Bingo!"<<endl;
}else if(answer==3)
{
cout<<"wrong answer!"<<endl;
}else if(answer==4)
{
cout<<"wrong answer!"<<endl;
}else
{
cout<<"you really are a dickhole!"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
張峻瑋
時間:
2013-10-19 18:16
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
char answer;
cout<<"<超腦殘問答>"<<endl;
cout<<"雞有幾顆頭?(a)1顆(b)2顆(c)3顆(d)無限多顆"<<endl;
cout<<"請作答!!!";
cin>>answer;
if(answer=='a')
{
cout<<"答對了!!好厲害!";
}
else if (answer=='b')
{
cout<<"智商-10000000000";
}
else if (answer=='c')
{
cout<<"恐怖啊!";
}
else if (answer=='d')
{
cout<<"慘了!雞變成了怪物";
}
else
{
cout<<"輸入錯誤!";
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉得旗
時間:
2013-10-25 18:39
include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{
int answer;
cout<<" 一, 選擇題"<<endl;
cout<<"請問你每天怎摸到教室上課?? (1)騎腳踏車(2)飛(3)走(4)開坦克車"<<endl;
cin >>answer;
{
if (answer==1)
cout << "?走廊怎摸騎腳踏車!"<<endl;
else if (answer==2)
cout<<"你不是超人!"<<endl;
else if (answer==3)
cout<<"賓果!!"<<endl;
else if (answer==4)
cout<<"我聽你在放屁!"<<endl;
else
cout<<"輸入錯誤"<<endl;
}
system ("pause");
return 0;
}
複製代碼
作者:
施伯叡
時間:
2013-10-26 09:35
本帖最後由 施伯叡 於 2013-10-26 16:32 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int ans;
cout << "超智障問答" <<endl;
cout << "請問水是什麼顏色" ;
cout << "(1)黃色 (2)紅色 (3)透明 (4)紫色" << endl;
cout << "請作答:" ;
cin >> ans ;
if (ans == 1)
{
cout << "去測一下你的智商吧" ;
}
else if (ans == 2)
{
cout << "犯案現場請勿靠近" ;
}
else if (ans == 3)
{
cout << "答對了,你的智商180";
}
else if (ans == 4)
{
cout << "你喝水溝的水喔";
}
else
{
cout << "別亂打" ;
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2