- #include<iostream>
- #include<cstdlib>
- #include<time.h>
- using namespace std;
- int main()
- {
- int player=0;
- int com=0;
- string mora[]={"剪刀","石頭","布"};
- cout<<"請出拳(1剪刀.2石頭3布)"<<endl;
- cin>>player;
- cout<<"電腦出拳中。。。"<<endl;
- srand(time(NULL));
- com=rand()%3+1;
- cout<<"電腦出"<<mora[com+1]<<endl ;
- if((player==1&&com==3))
- {
- cout<<"你贏了"<<endl;
- }
- else if((player==2&&com==1))
- {
- cout<<"你贏了"<<endl;
- }
- else if((player==3&&com==1))
- {
- cout<<"你贏了"<<endl;
- }
- else if(player=com)
- {
- cout<<"平手"<<endl;
- }
- else
- {
- cout<<"你輸了"<<endl;
- }
-
- system("pause");
- return 0;
- }
複製代碼 |