標題:
猜拳遊戲 (二)
[打印本頁]
作者:
方浩葦
時間:
2024-7-19 21:00
標題:
猜拳遊戲 (二)
以陣列存放 "剪刀" "石頭" "布",改寫上一個程式。
#include<iostream>
#include<cstdlib>
#include<ctime>
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;
}
複製代碼
作者:
林少謙
時間:
2024-7-20 15:39
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
re:
srand(time(NULL));
int p,c;
string a[]{"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>p;
c=rand()%3+1;
cout<<"你出"<<a[p-1]<<endl;
cout<<"電腦出"<<a[c-1]<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
劉奕劭
時間:
2024-7-20 15:54
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int p,c;
string a[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>p;
c=rand()%3+1;
cout<<"你出"<<a[p-1]<<endl;
cout<<"電腦出"<<a[c-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳妍蓁
時間:
2024-7-20 16:00
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main(){
re:
srand(time(NULL));
string n[]={"剪刀","石頭","布"};
int computer,player;
cout<<"請出拳 <1>剪刀 <2>石頭 <3>布"<<endl;
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;;
system("pause");
return 0;
}
複製代碼
作者:
洪榮辰
時間:
2024-7-20 16:11
#include<cstdlib>
#include<ctime>
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;
}
複製代碼
作者:
李偈睿
時間:
2024-7-20 16:21
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int player,pc;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
pc=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[pc-1]<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2