本帖最後由 劉漢文 於 2012-5-19 10:42 編輯
- #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<<"你抽到的牌是";
- if(b==1)
- {
- cout<<char(a)<<"A "<<endl;
- }
- if(b>=2 && b<=10)
- {
- cout<<char(a)<<b<<endl;
- }
- if(b==11)
- {
- cout<<char(a)<<"J "<<endl;
- }
- if(b==12)
- {
- cout<<char(a)<<"Q "<<endl;
- }
- if(b==13)
- {
- cout<<char(a)<<"K "<<endl;
- }
- cout<<"電腦抽到的牌是";
- c=rand()% 4+3;
- d=rand()% 13+1;
-
- if(d==1)
- {
- cout<<char(c)<<"A "<<endl;
- }
- if(d>=2 && d<=10)
- {
- cout<<char(c)<<d<<endl;
- }
- if(d==11)
- {
- cout<<char(c)<<"J "<<endl;
- }
- if(d==12)
- {
- cout<<char(c)<<"Q "<<endl;
- }
- if(d==13)
- {
- cout<<char(c)<<"K "<<endl;
- }
-
-
- if(d>b && a>c)
- {
- cout<<"你輸了!!!"<<endl;
- }if(d==b && a==c)
- {
- cout<<"平手!!"<<endl;
- }else
- {
- cout<<"你贏了"<<endl;
- }
-
- system("pause");
- return 0;
- }
複製代碼 |