標題:
猜拳遊戲 (二)
[打印本頁]
作者:
tonyh
時間:
2015-11-6 21:17
標題:
猜拳遊戲 (二)
本帖最後由 tonyh 於 2015-11-6 21:25 編輯
以陣列存放 "剪刀" "石頭" "布", 重寫上一個程式.
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
string name[3]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[computer-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
沈子耕
時間:
2015-11-6 21:35
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
re:
int pla,com;
string name[]={"剪刀","石頭","布"};
srand(time(NULL));
cout<<"請出拳! <1>剪刀 <2>石頭 <3>布 <0>不想玩了 ";
cin>>pla;
com=rand()%3+1;
if(pla==0)
goto end;
else if(pla==1||pla==2||pla==3)
cout<<"你出"<<name[pla-1]<<endl;
else{
cout<<"輸入錯誤"<<endl;
goto re;
}
if(com==1)
cout<<"電腦出剪刀!"<<endl;
else if(com==2)
cout<<"電腦出石頭!"<<endl;
else if(com==3)
cout<<"電腦出布!"<<endl;
cout<<"結果: ";
if(pla==com)
cout<<"平手"<<endl;
else if(pla==1&&com==3 || pla==2&&com==1 || pla==3&&com==2)
cout<<"恭喜您贏了"<<endl;
else if(pla==1&&com==2 || pla==2&&com==3 || pla==3&&com==1)
cout<<"恭喜電腦贏了"<<endl;
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
曾挺桂
時間:
2015-11-13 20:14
11111111111240111111111111
作者:
曾挺桂
時間:
2015-11-13 20:16
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
string name[3]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[computer-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳思惟
時間:
2015-11-13 20:16
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
string name[3]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[computer-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林侑成
時間:
2015-11-13 20:17
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
string name[3]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[computer-1]<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2