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