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