本帖最後由 許宸瑀 於 2022-2-26 11:40 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
-
- re:
- srand(time(NULL));
- int player,computer;
- string n[]={"剪刀","石頭","布"};
- cout<<"請出拳! (1)剪刀 (2)石頭 (3)布 ";
- cin>>player;
- computer=rand()%3+1;
- cout<<"你出"<<n[player-1]<<endl;
- cout<<"電腦出"<<n[computer-1]<<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;
- cout<<endl;
- goto re;
- system("pause");
- return 0;
- }
複製代碼- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
-
- int player, computer;
- string meth[3]= {"剪刀", "石頭", "布"};
- cout<<"請出拳! (1)"+meth[0]+" (2)"+meth[1]+" (3)"+meth[2]+": ";
- re:
- cin>>player;
- cout<<"你出"+meth[player-1]+"!"<<endl;
- srand(time(NULL));
- computer = rand()%3+1;
- cout<<"電腦"+meth[computer-1]+"!"<<endl;
-
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |