返回列表 發帖

任抽一張撲克牌

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

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.    srand(time(NULL));
  8.    re:
  9.    system("cls");
  10.    int a=rand()%4+3;
  11.    int b=rand()%13+1;

  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;
  23.     cout<<endl;     
  24.    
  25.     system("pause");
  26.      goto re;
  27.     return 0;



  28. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. using namespace std;
  5. int main()
  6. {
  7.     srand(time(NULL));
  8.     re:
  9.     system("cls");
  10.     int a ,b;
  11.     string n[]={"1","2","3","4","5","6","7","8","9","10","J","Q","K"};
  12.     a=rand()%4+3;
  13.     b=rand()%13;
  14.     cout<<"你抽到的牌是:"<<char(a)<<n[b]<<endl<<endl;
  15.     system("pause");
  16.     goto re;
  17.     return 0;
  18. }
複製代碼

TOP

返回列表