標題:
猜拳遊戲 (二)
[打印本頁]
作者:
tonyh
時間:
2016-8-27 10:47
標題:
猜拳遊戲 (二)
本帖最後由 tonyh 於 2016-8-27 11:20 編輯
以陣列存放 "剪刀" "石頭" "布", 重寫上一個程式.
#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;
}
複製代碼
作者:
黃茂勛
時間:
2016-8-27 11:04
本帖最後由 黃茂勛 於 2016-8-27 11:07 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re_start:
system("cls");
string name[3]={"剪刀","石頭","布"};
int player, computer;
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
srand(time(NULL));
computer=rand()%3+1;
if(player<1 || player>3)
goto re_start;
cout<<"你出"<<name[player-1]<<"!"<<endl;
cout<<"電腦出"<<name[computer-1]<<"!"<<endl;
system("pause");
goto re_start;
return 0;
}
複製代碼
作者:
高允懋
時間:
2016-8-27 11:05
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,c;
srand(time(NULL));
string n[3]={"剪刀","石頭","布"};
cout<<"請出拳 (1)剪刀 (2)石頭 (3)布 ";
cin>>p;
if(p<1 || p>3)
goto re;
cout<<"你出"<<n[p-1]<<endl;
c=rand()%3;
cout<<"電腦出"<<n[c]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陸長辰
時間:
2016-8-27 11:07
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
string name[3]={"剪刀","石頭","布"};
int player,computer;
cout<<"請出拳:(1)剪刀(2)石頭(3)布"<<endl;
cin>>player;
computer=rand()%3+1;
if(player<1 || player>3)
{
cout<<"不要亂"<<endl;
goto re;
}
cout<<"你出"<<name[player-1]<<endl;
cout<<"電腦出"<<name[computer-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳泓瑜
時間:
2016-8-27 11:15
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
rep:
system("cls");
string name[3]=("剪刀","石頭","布");
int plr,com;
srand(time(NULL));
com=rand()%3+1;
cout<<"請出拳 (1) 剪刀 (2) 石頭 (3) 布 :";
cin>>plr;
if(plr<1 || plr>4)
{
cout<<".......";
goto rep;
}
cout<<"你出 "<<name[plr-1]<<" ! "<<endl;
cout<<"電腦出 "<<name[com-1]<<" ! "<<endl;
system("pause");
goto rep;
return 0;
}
複製代碼
作者:
康湍榆
時間:
2016-9-3 09:58
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
string n[3]={"剪刀","石頭","布"};
cout<<"*****猜拳遊戲*****"<<endl;
cout<<"--------------------"<<endl;
cout<<"請出拳! (1)剪刀(2)石頭(3)布: ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
康湍榆
時間:
2016-9-3 12:05
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
re:
int player,computer;
string n[3]={"剪刀","石頭","布"};
cout<<"*****猜拳遊戲*****"<<endl;
cout<<"--------------------"<<endl;
cout<<"請出拳! (1)剪刀(2)石頭(3)布: ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
if(player==1 || computer==1)
{
cout<<"平手!"<<endl;
goto re;
}
else if(player==2 || computer==2)
{
cout<<"平手!"<<endl;
goto re;
}
else
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2