標題:
猜拳遊戲 (二)
[打印本頁]
作者:
tonyh
時間:
2017-4-15 14:15
標題:
猜拳遊戲 (二)
本帖最後由 tonyh 於 2020-1-3 14:39 編輯
以陣列存放 "剪刀" "石頭" "布",改寫上一個程式。
#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;
}
複製代碼
作者:
許紘誌
時間:
2017-4-15 14:47
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int a,b;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>a;
b=rand()%3+1;
cout<<"你出";
cout<<n[a-1]<<endl;
cout<<"電腦出";
cout<<n[b-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃宥鈞
時間:
2017-4-15 14:48
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
string yee[]={"剪刀","石頭","布 "};
cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<yee[player-1]<<endl;
cout<<"電腦出"<<yee[computer-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡幸融
時間:
2017-4-15 14:49
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x, y;
srand(time(NULL));
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! <1>剪刀 <2>石頭 <3>布 ";
cin>>x;
y=rand()%3+1;
cout<<"你出"<<n[x-1]<<endl;
cout<<"電腦出"<<n[y-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
洪榜蔓
時間:
2017-4-15 14:51
#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;
}
複製代碼
作者:
譚暐霖
時間:
2017-4-15 14:52
#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;
}
複製代碼
作者:
蕭澧邦
時間:
2017-4-21 18:07
#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;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2