標題:
猜拳遊戲 (二)
[打印本頁]
作者:
陳品肇
時間:
2022-2-26 10:36
標題:
猜拳遊戲 (二)
本帖最後由 陳品肇 於 2022-2-26 11:30 編輯
以陣列存放 "剪刀" "石頭" "布", 改寫上一個程式.
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int player, computer;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
cin>>player;
cout<<"你出"+meth[player-1]+"!"<<endl;
srand(time(NULL));
// 產出 1~3 亂數
computer = rand()%3+1;
cout<<"電腦"+meth[computer-1]+"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
黃奕澄
時間:
2022-2-26 11:33
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int player, computer;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
cin>>player;
cout<<"你出"+meth[player-1]+"!"<<endl;
srand(time(NULL));
computer = rand()%3+1;
cout<<"電腦"+meth[computer-1]+"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
曾善勤
時間:
2022-2-26 11:35
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int player, computer;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
cin>>player;
cout<<"你出"+meth[player-1]+"!"<<endl;
srand(time(NULL));
computer = rand()%3+1;
cout<<"電腦"+meth[computer-1]+"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
許馹東
時間:
2022-2-26 11:35
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int x, z;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
cin>>x;
cout<<"你出"+meth[x-1]+"!"<<endl;
srand(time(NULL));
z = rand()%3+1;
cout<<"電腦"+meth[z-1]+"!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
鍾易澄
時間:
2022-2-26 11:35
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int player, computer;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
cin>>player;
cout<<"你出"+meth[player-1]+"!"<<endl;
srand(time(NULL));
computer = rand()%3+1;
cout<<"電腦"+meth[computer-1]+"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林紘憲
時間:
2022-2-26 11:36
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int player, computer;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
cin>>player;
cout<<"你出"+meth[player-1]+"!"<<endl;
srand(time(NULL));
// 產出 1~3 亂數
computer = rand()%3+1;
cout<<"電腦"+meth[computer-1]+"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
孫子傑
時間:
2022-2-26 11:38
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int player, computer;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+"(1)"+meth[1]+"(2)"+meth[2]+":";
cin>>player;
cout<<"你出"+meth[player-1]+"!"<<endl;
srand(time(NULL));
computer = rand()%3+1;
cout<<"電腦"+meth[computer-1]+"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
許宸瑀
時間:
2022-2-26 11:38
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int player, computer;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
cin>>player;
cout<<"你出"+meth[player-1]+"!"<<endl;
srand(time(NULL));
computer = rand()%3+1;
cout<<"電腦"+meth[computer-1]+"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
田家齊
時間:
2022-2-26 11:40
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int a,b;
srand(time(NULL));
string x[3]={"剪刀","石頭","布"};
cout<<"請出拳(1)"+x[0]+"(2)"+x[1]+"(3)"+x[2]+":";
cin>>a;
b=rand()%3+1;
cout<<"你出"+x[a-1]+"!"<<endl;
cout<<"電腦出"+x[b-1]+"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
徐譽豈
時間:
2022-2-26 11:45
include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int player,computer;
string meth[]={"剪刀","石頭","布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+":";
cin>>player;
cout<<"你出"+meth[player-1]+"!"<<endl;
srand(time(NULL));
computer = rand()%3+1;
cout<<"電腦"+meth[computer-1]+"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
高鋐鈞
時間:
2022-2-26 11:45
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int x,y;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
cin>>x;
cout<<"你出"+meth[x-1]+"";
srand(time(NULL));
y=rand()%3+1;
cout<<"電腦出"+meth[y-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
郭博鈞
時間:
2022-2-26 11:46
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int player, computer;
string meth[3]={"剪刀","石頭","布"};
cout<<"請出拳! (1)"+meth[0]+"(2)"+meth[1]+"(3)"+meth[2]+": ";
cin>>player;
computer=rand()%3+1;
cout<<"你出"<<meth[player-1]<<"!"<<endl;
srand(time(NULL));
computer = rand()%3+1;
cout<<"電腦出"+meth[computer-1]+"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林鴻慶
時間:
2022-3-5 09:14
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int player, computer;
string meth[3]= {"剪刀", "石頭", "布"};
cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
cin>>player;
cout<<"你出"+meth[player-1]+"!"<<endl;
srand(time(NULL));
computer = rand()%3+1;
cout<<"電腦"+meth[computer-1]+"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
柳侑辰
時間:
2022-3-5 09:37
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int player,computer;
string go[3]={"剪刀","石頭","布"};
cout<<"請出拳! (1)"+go[0]+"(2)"+go[1]+"(3)"+go[2]+":";
cin>>player;
cout<<"你出"+go[player-1]+"!"<<endl;
srand(time(NULL));
computer=rand()%3+1;
cout<<"電腦"+go[computer-1]+"!"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2