標題:
猜拳遊戲 (二)
[打印本頁]
作者:
tonyh
時間:
2021-1-16 20:17
標題:
猜拳遊戲 (二)
以陣列存放 "剪刀" "石頭" "布",改寫上一個程式。
#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;
}
複製代碼
作者:
黃子倢
時間:
2021-1-16 20:26
本帖最後由 黃子倢 於 2021-1-16 20:43 編輯
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int player, computer;
srand(time(NULL));
string n[]={"剪刀","石頭","布"};
re:
cout<<"請出拳: (1)剪刀(2)石頭(3)布"<<endl;
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<"!"<<endl;
cout<<"電腦"<<n[computer-1]<<"!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
李柏穎
時間:
2021-1-16 20:26
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
srand(time(NULL));
int a, b;
string n[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)剪刀(2)石頭(3)布: ";
cin>>a;
b=rand()%3+1; //1~3
cout<<"你出"<<n[a-1]<<"!"<<endl;
cout<<"電腦出"<<n[b-1]<<"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
王宇崴
時間:
2021-1-16 20:27
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player,computer;
string n[]={"剪刀","石頭","布"};
re:
cout<<"請出拳!(1)剪刀(2)石頭(3)布 ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<n[player-1]<<endl;
cout<<"電腦出"<<n[computer-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
余柏緯
時間:
2021-1-16 20:29
#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;
}
複製代碼
作者:
朱奕祐
時間:
2021-1-16 20:30
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
int player,computer;
string n[3]={"剪刀","石頭","布"};
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;
}
複製代碼
作者:
許洧熏
時間:
2021-1-16 20:34
#include<iostream>
#include<cstdlib>
#include<ctime>
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;
}
複製代碼
作者:
呂尚霖
時間:
2021-1-16 20:36
本帖最後由 呂尚霖 於 2021-1-23 20:02 編輯
#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