標題:
switch 敘述
[打印本頁]
作者:
tonyh
時間:
2011-10-1 16:12
標題:
switch 敘述
試利用 switch 敘述, 設計一個簡單的選擇題.
本帖隱藏的內容需要回復才可以瀏覽
作者:
t2364705
時間:
2011-10-1 16:28
本帖最後由 t2364705 於 2012-4-14 16:19 編輯
#include<iostream>
using namespace std;
int main()
{
int answer;
cout<<"猜猜我今年幾歲?"<<endl;
cout<<"(1) 五歲 (2) 十歲 (3) 十五歲 (4) 二十歲"<<endl;
cin>>answer;
cout<<endl;
switch (answer)
{
case 1:
cout<<"我有那麼年輕嗎!";
break;
case 2:
cout<<"賓果!你答對了!";
break;
case 3:
cout<<"白痴!我沒有那麼老!";
break;
case 4:
cout<<"你是來亂的喔!";
default:
cout<<"輸入錯誤";
}
system("pause");
return 0 ;
}
複製代碼
作者:
t3742238
時間:
2011-10-1 16:29
#include<iostream>
using namespace std ;
int main()
{
int answer;
cout<<"請問老師幾歲";
cout<<"30~35";
cin>>answer;
cout<<endl;
switch(answer)
{
case 30:
cout<<"好年輕歐(笑死我)";
break;
case 31:
cout<<"接近了在高一點";
break;
case 32:
cout<<"正確!你是怎麼猜到的??";
break;
case 33:
cout<<"再降低一點";
break;
case 34:
cout<<"有大腦的人不會這樣選";
break;
case 35:
cout<<"你猜~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~錯了";
break;
default:
cout<<"輸入歲數 呆~~子~~";
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉漢文
時間:
2011-10-1 16:31
#include <iostream>
using namespace std;
int main()
{
int answer;
cout<<"猜猜看我幾今年幾歲"<<endl;
cout<<"(1)1歲 (2)5歲 (3)12歲 (4)100歲"<<endl;
cout<<"請做答.....";
cin>>answer;
cout<<endl;
switch(answer)
{
case 1:
cout<<"一歲就會用電腦了嗎?";
break;
case 2:
cout<<"五歲就會寫程式了嗎?";
break;
case 3:
cout<<"答對了!";
break;
case 4:
cout<<"變人瑞了啦!";
break;
default:
cout<<"沒有這個選擇";
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
尤泓鈞
時間:
2011-10-1 16:34
#include<iostream>
using namespace std;
int main()
{
int answer;
cout<<"猜猜看我幾歲??"<<endl;
cout<<"(1)2歲(2)5歲(3)12歲(4)30歲"<<endl;
cout<<"請作答...";
cin>>answer;
cout<<endl;
switch(answer)
{
case 1:
cout<<"2歲??你兩歲寫程式給我看!!";
break;
case 2:
cout<<"5歲?嗯嗯...有可能,不過我沒那嚜麼聰明!!";
break;
case 3:
cout<<"12歲!聰明答對了!!";
break;
case 4:
cout<<"30歲?!夭壽!!我沒那麼老!!";
break;
default:
cout<<"沒這種選擇!!";
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
t8155745
時間:
2011-10-1 16:35
#include<iostream>
using namespace std;
int main()
{
int answer;
cout<<"猜猜我今年幾歲?"<<endl;
cout<<"(1) 五歲 (2) 十歲 (3) 十五歲 (4) 二十歲"<<endl;
cin>>answer;
cout<<endl;
switch (answer)
{
case 1:
cout<<"我有那麼年輕嗎!";
break;
case 2:
cout<<"賓果!你答對了!";
break;
case 3:
cout<<"白痴!我沒有那麼老!";
break;
case 4:
cout<<"你是來亂的喔!";
default:
cout<<"輸入錯誤";
}
system("pause");
return 0 ;
}
複製代碼
作者:
許逸瑋
時間:
2011-10-1 16:39
#include <iostream>
using namespace std;
int main()
{
int answer;
cout<<"猜猜someone今年心智年齡幾歲?"<<endl;
cout<<"(1) 1歲 (2) 13歲 (3) 20歲 (4) 40歲"<<endl;
cin>>answer;
cout<<endl;
switch (answer)
{
case 1:
cout<<"有那麼年輕嗎!";
break;
case 2:
cout<<"賓果!你答對了!";
break;
case 3:
cout<<"沒有那麼老啦!";
break;
case 4:
cout<<"你是來亂的喔!";
default:
cout<<"輸入錯誤";
}
system("pause");
return 0 ;
}
複製代碼
作者:
蔡昀佑
時間:
2011-10-1 16:48
#include<iostream>;
using namespace std;
int main()
{
int answer;
cout<<"請問我幾歲???"<<endl;
cout<<"(1)0歲(2)11歲(3)111歲(4)25歲"<<endl;
cout<<"答...";
cin>>answer;
cout<<endl;
switch(answer)
{
case 1:
cout<<"笨!";
break;
case 2:
cout<<"答對了!!";
break;
case 3:
cout<<"在天國...";
break;
case 4:
cout<<"不對";
break;
defauit:
cout<<"x";
}
cout<<endl;
system("pause");
return 0;
}
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2