標題:
猜拳遊戲 (二)
[打印本頁]
作者:
tonyh
時間:
2015-5-9 10:37
標題:
猜拳遊戲 (二)
本帖最後由 tonyh 於 2015-5-9 11:43 編輯
以陣列存放 "剪刀" "石頭" "布", 重寫上一個程式.
[attach]1236[/attach]
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player, computer;
string name[3]={"剪刀","石頭","布"}; //name[0] name[1] name[2]
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>player;
cout<<"你出"<<name[player-1]<<"!"<<endl;
computer=rand()%3+1;
cout<<"電腦出"<<name[computer-1]<<"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
洪振庭
時間:
2015-5-9 11:33
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int p,c;
string name[3]={"刀","石","網"};
cout<<"請出拳! (1)刀(2)石(3)網 ";
cin>>p;
cout<<"你出"<<name[p-1]<<endl;
c=rand()%3+1;
cout<<"電腦出"<<name[p-1]<<endl;
system("pause");
return 0;
}
複製代碼
作者:
李知易
時間:
2015-5-9 11:33
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int game, com;
string name[3]={"剪刀","石頭","布"};
cout<<"請出拳! <1>剪刀 <2>石頭 <3>布 ";
cin>>game;
cout<<"你出"<<name[game-1]<<"!"<<endl;
com=rand()%3+1;
cout<<"電腦出"<<name[com-1]<<"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
謝瀞儀
時間:
2015-5-9 11:44
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
srand(time(NULL));
string name[3]={"剪刀","石頭","布"};
int player, computer;
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>player;
cout<<"你出"<<name[player-1]<<"!"<<"\n";
computer=rand()%3+1;
cout<<"電腦出"<<name[computer-1]<<"!"<<"\n";
goto re;
system("pause");
return 0;
}
複製代碼
作者:
李大全
時間:
2015-5-9 11:44
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player, computer;
string name[3]={"剪刀","石頭","布"}; //name[0] name[1] name[2]
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
cin>>player;
cout<<"你出"<<name[player-1]<<"!"<<endl;
computer=rand()%3+1;
cout<<"電腦出"<<name[computer-1]<<"!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
謝瀞儀
時間:
2015-5-16 11:01
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
srand(time(NULL));
int player, computer;
string name[3]={"剪刀","石頭","布"};
re:
cout<<"請出拳! (1)剪刀 (2)石頭 (3)布"<<endl;
cin>>player;
cout<<"你出"<<name[player-1]<<"!"<<endl;
computer=rand()%3+1;
cout<<"電腦出"<<name[computer-1]<<"!"<<endl;
if((player==1 and computer==3)or(player==2 and computer==1)or(player==3 and computer==2))
cout<<"you win!!"<<endl;
else if((player==1 and computer==2)or(player==2 and computer==3)or(player==3 and computer==1))
cout<<"you lose!!"<<endl;
else
cout<<"fair!!"<<endl;
goto re;
system("pause");
return 0;
}
複製代碼
作者:
梁和雋
時間:
2015-5-19 07:19
#include <iostream>
#include <cstdlib>;
using namespace std;
int main()
{
srand(time(NULL));
int a, b, c;
re:
string name[3]={"剪刀","石頭","布"};
cout<<"請輸入你出的拳"<<endl<<"(1)剪刀:, (2)石頭:, (3)布:"<<endl;
cin>>a;
cout<<"你出"<<name[a-1]<<endl;
if(a>0 && 4<0 )
{
for(int i=1; i>=0; i++)
cout<<rand()<<"錯誤! (。凡。''') orz";
}
b=rand()%3+1;
cout<<"電腦出"<<name[b-1]<<endl;
if(a==b)
cout<<"平手"<<endl;
else if(a-b==1)
cout<<"you win"<<endl;
else if(b-a==2)
cout<<"you win"<<endl;
else
cout<<"you lose"<<endl;
goto re;
system ("pause") ;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2