本帖最後由 洪榮辰 於 2024-7-20 16:24 編輯
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- re:
- srand(time(NULL));
- int p, c;
- string n[]={"剪刀","石頭","布"};
- cout<<"請出拳! (1)剪刀(2)石頭(3)布 ";
- cin>>p;
- c=rand()%3+1;
- cout<<"你出"<<n[p-1]<<"!"<<endl;
- cout<<"電腦出"<<n[c-1]<<"!"<<endl;
- if(p==c)
- {cout<<"平手!"<<endl;}
- else if(p==1 && c==2)
- {cout<<"你輸了!"<<endl;}
- else if(p==1 && c==3)
- {cout<<"你贏了!"<<endl;}
- else if(p==2 && c==1)
- {cout<<"你贏了!"<<endl;}
- else if(p==2 && c==3)
- {cout<<"你輸了!"<<endl;}
- else if(p==3 && c==1)
- {cout<<"你輸了!"<<endl;}
- else if(p==3 && c==2)
- {cout<<"你贏了!"<<endl;}
- cout<<endl;
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |