- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- srand(time(NULL));
- string name[3]={"剪刀","石頭","布"};
- int player,computer;
- cout<<"請出拳:(1)剪刀(2)石頭(3)布"<<endl;
- cin>>player;
- computer=rand()%3+1;
- if(player<1 || player>3)
- {
- cout<<"不要亂"<<endl;
- goto re;
- }
- cout<<"你出"<<name[player-1]<<endl;
- cout<<"電腦出"<<name[computer-1]<<endl;
- system("pause");
- return 0;
- }
複製代碼 |