標題:
猜拳遊戲 (二)
[打印本頁]
作者:
tonyh
時間:
2020-1-17 20:10
標題:
猜拳遊戲 (二)
以陣列存放 "剪刀" "石頭" "布",改寫上一個程式。
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1; //1~3
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
李宇澤
時間:
2020-1-17 20:19
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
re:
int player,computer;
string a[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<a[player-1]<<endl;
cout<<"電腦出"<<a[computer-1]<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
余有晉
時間:
2020-1-17 20:19
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
re:
int player,computer;
string n[]={"屌爆刀","硬頭","如來神掌"};
cout<<"請出拳! (1)屌爆刀(2)硬頭(3)如來神掌 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
黃宥華
時間:
2020-1-17 20:20
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand (time(NULL));
pun:
int d,f;
string n[]={"剪刀","石頭","布"};
cout<<"還不快出 1.剪刀 2.石頭 3.布"<<endl;
cin>>d;
f=rand()%3+1;
cout<<"你出"<<n[d-1]<<endl;
cout<<"電腦出"<<n[f-1]<<endl;
goto pun;
system("pause");
return 0;
}
複製代碼
作者:
黃辰昊
時間:
2020-1-17 20:20
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int player, computer;
re:
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! <1>剪刀 <2>石頭 <3>布";
cin>>player;
computer=rand()%3+1
cout<<"你出"<<n[player-1]<<"!"<<endl;
cout<<"電腦出"<<n[computer-1]<<"!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
孫嘉駿
時間:
2020-1-17 20:21
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
re:
int f,t;
string d[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>f;
t=rand()%3+1;
cout<<"你出"<<d[f-1]<<endl;
cout<<"電腦出"<<d[t-1]<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
蔡忻霓
時間:
2020-1-17 20:22
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
sting n[]={"剪刀","石頭","布"}
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
董宸佑
時間:
2020-1-17 20:22
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
string n[]={"剪刀","石頭","布"};
int p,c;
re:
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 -> ";
cin>>p;
c=rand()%3+1;
cout<<"你出"<<n[p-1]<<"!"<<endl;
cout<<"電腦出"<<n[c-1]<<"!"<<endl<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
陳宥穎
時間:
2020-1-17 20:22
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int pl,co;
string a[]={"剪刀","石頭","布"};
s:
srand(time(NULL));
cout<<"請出拳! (1)剪刀(2)石頭(3)布\n ";
cin>>pl;
cout<<"你出"<<a[pl-1]<<endl;
co=rand()%3+1;
cout<<"電腦出"<<a[co-1]<<endl;
goto s;
system("pause>nul");
return 0;
}
複製代碼
作者:
林政瑜
時間:
2020-1-17 20:22
本帖最後由 林政瑜 於 2020-1-17 20:27 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2