本帖最後由 田家齊 於 2022-2-26 12:02 編輯
- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- re:
- int a,b;
- srand(time(NULL));
- string x[3]={"剪刀","石頭","布"};
- cout<<"請出拳(1)"+x[0]+"(2)"+x[1]+"(3)"+x[2]+":";
- cin>>a;
- b=rand()%3+1;
- cout<<"你出"+x[a-1]+"!"<<endl;
- cout<<"電腦出"+x[b-1]+"!"<<endl;
- if(a==b)
- {
- cout<<"平手"<<endl;
- } else if(
- (a==1&&b==3)|| (a==2&&b==1)|| (a==3&&b==2)
- )
- {
- cout<<"玩家贏"<<endl;
- } else
- {
- cout<<"電腦贏"<<endl;
- }
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |