- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int player, computer;
- re:
- cout<<"請出拳!! (1)剪刀 (2)石頭 (3)布 "<<endl;
- cin>>player;
- if(player==1)
- {
- cout<<"你出剪刀!!"<<endl;
- }
- else if(player==2)
- {
- cout<<"你出石頭!!"<<endl;
- }
- else
- {
- cout<<"你出布!!"<<endl;
- }
-
- srand(time(NULL));
- computer=rand()%3+1;
- if (computer==1)
- {
- cout<<"電腦出剪刀!!"<<endl;
- }
- else if(computer==2)
- {
- cout<<"電腦出石頭!!"<<endl;
- }
- else
- {
- cout<<"電腦出布!!"<<endl;
- }
-
- if (player==computer)
- {
- cout<<"平手!!"<<endl;
-
- }
- 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;
- }
複製代碼 |