Board logo

標題: 任抽一張撲克牌 [打印本頁]

作者: tonyh    時間: 2014-1-11 15:02     標題: 任抽一張撲克牌

本帖最後由 tonyh 於 2014-1-17 18:54 編輯

設計一小程式, 可以隨機地顯示整組52張撲克牌中的任一張牌號.
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     int a, b;
  7.     srand(time(NULL));
  8.     re:
  9.     a=rand()%4+3;
  10.     b=rand()%13+1;
  11.     cout<<"您所抽到的牌是: ";
  12.     cout<<char(a);
  13.     if(b==1)
  14.         cout<<"A"<<endl;
  15.     else if(b==11)
  16.         cout<<"J"<<endl;
  17.     else if(b==12)
  18.         cout<<"Q"<<endl;
  19.     else if(b==13)
  20.         cout<<"K"<<endl;
  21.     else
  22.         cout<<b<<endl;
  23.     system("pause");
  24.     goto re;
  25.     system("pause");   
  26.     return 0;   
  27. }
複製代碼

作者: 張瀚仁    時間: 2014-1-11 15:17

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     int a,b;
  7.     srand(time(NULL));
  8.     re:
  9.     a=rand()%4+3;
  10.     b=rand()%13+1;
  11.     cout<<"你抽到的牌是:";
  12.     cout<<char(a);
  13.     if(b==1)
  14.     cout<<"A"<<endl;
  15.     else  if(b==11)
  16.     cout<<"J"<<endl;
  17.     else  if(b==12)
  18.     cout<<"Q"<<endl;
  19.     else  if(b==13)
  20.     cout<<"K"<<endl;
  21.     else
  22.     cout<<b<<endl;
  23.     system("pause");
  24.     goto re;
  25.     system("pause");   
  26.     return 0;   
  27. }
複製代碼

作者: 許逸群    時間: 2014-1-11 15:17

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {   
  6.     int a,b;
  7.     srand(time(NULL));
  8.     re:
  9.     a=rand()%4+3;
  10.     b=rand()%13+1;
  11.     cout<<"你抽到的牌是:";
  12.     cout<<char(a);
  13.     if(b==1)
  14.     cout<<"A"<<endl;
  15.     else  if(b==11)
  16.     cout<<"J"<<endl;
  17.     else  if(b==12)
  18.     cout<<"Q"<<endl;
  19.     else  if(b==13)
  20.     cout<<"K"<<endl;
  21.     else
  22.     cout<<b<<endl;
  23.     system("pause");
  24.     goto re;
  25.     system("pause");   
  26.     return 0;   
  27. }
複製代碼

作者: 林以諾    時間: 2014-1-11 15:18

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a,b;
  7.     srand(time(NULL));
  8.     re:
  9.     a=rand()%4+3;
  10.     b=rand()%13+1;
  11.     if(a==1)
  12.     cout<<char(a)<<"A"<<endl;
  13.     if(a>1 && a<11)
  14.     cout<<char(a)<<b<<endl;
  15.     if(a==11)
  16.     cout<<char(a)<<"J"<<endl;
  17.     if(a==12)
  18.     cout<<char(a)<<"Q"<<endl;
  19.     if(a==13)
  20.     cout<<char(a)<<"K"<<endl;
  21.     system("pause");
  22.     goto re;
  23.     system("pause");
  24.     return 0;   
  25. }
複製代碼

作者: 鎧言    時間: 2014-1-11 15:19

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a,b;
  7.     srand(time(NULL));
  8.     re:
  9.     a=rand()%4+3;
  10.     b=rand()%13+1;
  11.     if(a==1)
  12.     cout<<char(a)<<"A"<<endl;
  13.     if(a>1 && a<11)
  14.     cout<<char(a)<<b<<endl;
  15.     if(a==11)
  16.     cout<<char(a)<<"J"<<endl;
  17.     if(a==12)
  18.     cout<<char(a)<<"Q"<<endl;
  19.     if(a==13)
  20.     cout<<char(a)<<"K"<<endl;
  21.     system("pause");
  22.     goto re;
  23.     system("pause");
  24.     return 0;   
  25. }
複製代碼

作者: 劉泳鱔    時間: 2014-1-11 15:23

本帖最後由 劉泳鱔 於 2014-1-11 15:25 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a, b;
  7.     srand(time(NULL));
  8.     re:
  9.     a=rand()%4+3;
  10.     b=rand()%13+1;
  11.     cout<<"你抽的是: ";
  12.     cout<<char(a);
  13.     if(b==1)
  14.     cout<<"A"<<endl;
  15.     else if(b==11)
  16.     cout<<"J"<<endl;
  17.     else if(b==12)
  18.     cout<<"Q"<<endl;
  19.     else if(b==13)
  20.     cout<<"K"<<endl;
  21.     else
  22.     cout<<b<<endl;
  23.     system("pause");
  24.     goto re;
  25.     system("pause");
  26.     return 0;   
  27. }
複製代碼
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a, b;
  7.     srand(time(NULL));
  8.     re:
  9.     a=rand()%4+3;
  10.     b=rand()13+1
  11.     cout<<"你抽的是: ";
  12.     cout<<char(a)
  13.     if(b==1)
  14.     cout<<"A"<<endl;
  15.     else if(b==11)
  16.     cout<<"j"<<endl;
  17.     else  if(b==12)
  18.     cout<<"Q"<<endl;
  19.     else  if(b==13)
  20.     cout<<"K"<<endl;
  21.     else
  22.     cout<<b<<endl;
  23.     system("pause");
  24.     goto re;
  25.     system("pause");
  26.     return 0;   
  27. }
複製代碼

作者: 郭凡瑛    時間: 2014-1-11 15:24

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a,b;
  7.     srand(time(NULL));
  8.     re:
  9.     a=rand()%4+3;
  10.     b=rand()%13+1;
  11.     cout<<"你抽到的是: ";
  12.     cout<<char(a);
  13.     if(b==1)
  14.     cout<<"A"<<endl;
  15.     else  if(b==11)
  16.     cout<<"J"<<endl;
  17.     else  if(b==11)
  18.     cout<<"Q"<<endl;
  19.     else  if(b==11)
  20.     cout<<"K"<<endl;
  21.     else
  22.     cout<<b<<endl;
  23.     system("pause");
  24.     goto re;
  25.     system("pause");
  26.     return 0;   
  27. }
複製代碼

作者: 黃崇維    時間: 2014-1-17 18:53

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a, b;
  7.     srand(time(NULL));
  8.     re:
  9.     a=rand()%4+3;
  10.     b=rand()%13+1;
  11.     cout<<"你所抽到的牌是: ";
  12.     cout<<char(a);
  13.     if(b==1)
  14.         cout<<"A"<<endl;
  15.     else if(b==11)
  16.         cout<<"J"<<endl;
  17.     else if(b==12)
  18.         cout<<"Q"<<endl;
  19.     else if(b==13)
  20.         cout<<"K"<<endl;
  21.     else
  22.         cout<<b<<endl;
  23.     system("pause");
  24.     goto re;         
  25.     system("pause");
  26.     return 0;
  27. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2