- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- re:
- int player, computer;
- cout<<"請出拳! (1)剪刀(2)石頭(3)布";
- cin>>player;
- if(player==1)
- {
- cout<<"你出剪刀"<<endl;
- }else if(player==2)
- {
- cout<<"你出石頭"<<endl;
- }else
- {
- cout<<"你出布"<<endl;
- }
- srand (time(NULL));
- computer=rand()%3+1;
- if(player==computer)
- {
- cout<<"平手!";
- }else if((player==1&&computer==3)||
- (player==2&&computer==1)||
- (player==3&&computer==2))
- {
- cout<<"我贏了!"<<endl;
- }else
- {
- cout<<"我輸了!!"<<endl;
- }
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |