- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int a,b,c,d;
- srand(time(NULL));
- a=rand()%4+3;
- b=rand()%13+1;
- cout<<"你抽到的牌是: ";
- cout<<char(a);
- if(b==1)
- cout<<"A"<<endl;
- else if(b==11)
- cout<<"J"<<endl;
- else if(b==12)
- cout<<"Q"<<endl;
- else if(b==13)
- cout<<"K"<<endl;
- else
- cout<<b<<endl;
- c=rand()%4+3;
- d=rand()%13+1;
- cout<<"電腦抽到的牌是: ";
- cout<<char(c);
- if(d==1)
- cout<<"A"<<endl;
- else if(d==11)
- cout<<"J"<<endl;
- else if(d==12)
- cout<<"Q"<<endl;
- else if(d==13)
- cout<<"K"<<endl;
- else
- cout<<d<<endl;
- if(b>d)
- cout<<"你贏了"<<endl;
- else if(b<d)
- cout<<"電腦贏了"<<endl;
- else if(b==d)
- cout<<"平手"<<endl;
- system("pause");
- system("pause");
- return 0;
- }
複製代碼 |