- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main()
- {
- re:
- int x,y;
- 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]+"";
- srand(time(NULL));
- y=rand()%3+1;
- cout<<"電腦出"+meth[y-1]<<endl;
- if(y==x)
- cout<<"平手"<<endl;
- else if((x==1 && y==3)||(x==2&&y==1)||(x==3&&y==2))
- cout<<"你贏了!"<<endl;
- else{
- cout<<"電腦贏了"<<endl;
- }
- goto re;
- system("pause");
- return 0;
- }
複製代碼 |