標題:
猜拳遊戲 (一)
[打印本頁]
作者:
tonyh
時間:
2019-3-23 10:25
標題:
猜拳遊戲 (一)
運用產生隨機亂數的技巧, 設計一個猜拳遊戲,
使用者可以選擇出剪刀石頭或布, 電腦隨機出拳.
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出";
if(player==1)
cout<<"剪刀!"<<endl;
else if(player==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
cout<<"電腦出";
if(computer==1)
cout<<"剪刀!"<<endl;
else if(computer==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
湯郡一
時間:
2019-3-23 10:58
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出";
if(player==1)
cout<<"剪刀!"<<endl;
else if(player==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
cout<<"電腦出";
if(computer==1)
cout<<"剪刀!"<<endl;
else if(computer==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蘇昱全
時間:
2019-3-23 11:06
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
cout<<"請出拳!(1)剪刀(2)石頭(3)布"<<endl;
cin>>player;
computer=rand()%3+1;
cout<<"你出";
if(player==1)
cout<<"剪刀!"<<endl;
if(player==2)
cout<<"石頭!"<<endl;
else if(player==3)
cout<<"布!"<<endl;
else
cout<<"輸入錯誤!"<<endl;
cout<<"電腦出";
if(computer==1)
cout<<"剪刀!"<<endl;
else if(computer==2)
cout<<"石頭!"<<endl;
else
cout<<"布!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
田宇任
時間:
2019-3-23 11:06
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
int a,c;
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>a;
cout<<endl;
c=rand()%3+1;
if(a==1)
{
cout<<"你出剪刀"<<endl;
cout<<endl;
}
else if(a==2)
{
cout<<"你出石頭"<<endl;
cout<<endl;
}
else if(a==3)
{
cout<<"你出布"<<endl;
cout<<endl;
}
else
{
cout<<"輸入錯誤"<<endl;
cout<<endl;
goto re;
}
cout<<"電腦出";
if(c==1)
{
cout<<"剪刀"<<endl;
cout<<endl;
}
else if(c==2)
{
cout<<"石頭"<<endl;
cout<<endl;
}
else if(c==3)
{
cout<<"布"<<endl;
cout<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2