標題:
[作業] 任抽一張撲克牌與電腦比大小
[打印本頁]
作者:
tonyh
時間:
2014-1-11 15:28
標題:
[作業] 任抽一張撲克牌與電腦比大小
本帖最後由 tonyh 於 2014-1-11 15:31 編輯
設計一小程式, 可以隨機地顯示整組52張撲克牌中的任一張牌號, 並與電腦比大小, 電腦同樣也是隨機抽牌喔. 不考慮花色, 只考慮牌面上的值, 如果值比電腦大則顯示"你贏了", 同理類推.
[attach]793[/attach]
作者:
鎧言
時間:
2014-1-11 17:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c,d;
srand(time(NULL));
re:
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");
goto re;
system("pause");
return 0;
}
複製代碼
作者:
林以諾
時間:
2014-1-12 13:41
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a, b ,c ,d ,bigger;
srand(time(NULL));
re:
a=rand()%4+3;
b=rand()%13+1;
c=rand()%4+3;
d=rand()%13+1;
cout<<"你抽到的牌是: "<<char(a);
if(b==1)
cout<<"A"<<endl;
if(b>1 && b<11)
cout<<b<<endl;
if(b==11)
cout<<"J"<<endl;
if(b==12)
cout<<"Q"<<endl;
if(b==13)
cout<<"K"<<endl;
cout<<"電腦抽到的牌是: "<<char(c);
if(d==1)
cout<<"A"<<endl;
if(d>1 && d<11)
cout<<d<<endl;
if(d==11)
cout<<"J"<<endl;
if(d==12)
cout<<"Q"<<endl;
if(d==13)
cout<<"K"<<endl;
if(b>d)
cout<<"你贏了!"<<endl;
else if(d>b)
cout<<"你輸了!"<<endl;
else
cout<<"平手!"<<endl;
system("pause");
goto re;
system("pause");
return 0;
}
複製代碼
作者:
黃崇維
時間:
2014-1-17 19:09
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c,d;
srand(time(NULL));
re:
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");
goto re;
system("pause");
return 0;
}
複製代碼
作者:
劉泳鱔
時間:
2014-1-17 22:26
#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;
}
複製代碼
作者:
張瀚仁
時間:
2014-1-18 10:19
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c,d;
srand(time(NULL));
re:
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;
if(k>=10)
goto end;
system("pause");
goto re;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2