- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- int player ,computer;
- cout<<"請出拳 (1)剪刀 (2)石頭 (3)布";
- cin>>player;
- bb:
- if(player==1)
- {
- cout<<"你出剪刀!"<<endl;
- }else if(player==2)
- {
- cout<<"你出石頭!"<<endl;
- }else if(player==3)
- {
- cout<<"你出布!"<<endl;
- }else
- {
- cout<<"輸入錯誤!"<<endl;
- goto bb;
- }
- 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;
- }
複製代碼 |