標題:
猜拳遊戲 (二)
[打印本頁]
作者:
tonyh
時間:
2019-3-23 10:57
標題:
猜拳遊戲 (二)
以陣列存放 "剪刀" "石頭" "布", 改寫上一個程式.
#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;
}
複製代碼
作者:
湯郡一
時間:
2019-3-23 11:06
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
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;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
田宇任
時間:
2019-3-23 11:20
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
int a,c;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>a;
cout<<endl;
c=rand()%3+1;
cout<<"你出"<<n[a-1]<<endl;
cout<<endl;
cout<<"電腦出"<<n[c-1]<<endl;
cout<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
蘇昱全
時間:
2019-3-23 11:26
#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://seed.istak.org.tw/)
Powered by Discuz! 7.2