返回列表 發帖

[作業] 撲克牌整組顯示

本帖最後由 tonyh 於 2012-5-12 16:20 編輯

利用ASCII碼轉換成字元, 搭配巢狀迴圈, 在螢幕上顯示出整組撲克牌如下:
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     for(int i=3; i<=6; i++)
  7.     {
  8.           cout<<char(i)<<"A ";
  9.           for(int j=2; j<=10; j++)
  10.           {
  11.                cout<<char(i)<<j<<" ";
  12.           }
  13.           cout<<char(i)<<"J "<<char(i)<<"Q "<<char(i)<<"K ";        
  14.           cout<<endl;
  15.     }
  16.     system("pause");
  17.     return 0;   
  18. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

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

  33. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. for(int i=3; i<=6;i++)
  7. {
  8.         cout<<char(i)<<"A ";
  9.         for(int j=2; j<=10;j++)
  10.         {
  11.                 cout<<char(i)<<j<<" ";
  12.         }
  13.         cout<<char(i)<<"J "<<char(i)<<"Q "<<char(i)<<"K ";
  14.         cout<<endl;
  15. }
  16.     system("pause");
  17.     return 0;   

  18. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     for(int i=3; i<=6; i++)
  7.     {
  8.             cout<<char(i)<<"A ";
  9.             for(int j=2 ;j<=10 ;j++)
  10.             {
  11.                     cout<<char(i)<<j<<" ";
  12.             }
  13.             cout<<char(i)<<"J "<<char(i)<<"Q "<<char(i)<<"K ";
  14.             cout<<endl;   
  15.     }
  16.    


  17.     system("pause");
  18.     return 0;   

  19. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     for(int i=3; i<=6; i++)
  7.     {
  8.             cout<<char(i)<<"A ";
  9.             for(int j=2; j<=10; j++)
  10.             {
  11.                     cout<<char(i)<<j<<" ";
  12.             }
  13.             cout<<char(i)<<"j "<<char(i)<<"Q "<<char(i)<<"K ";
  14.             cout<<endl;
  15.     }
  16.     system("pause");
  17.     return 0;   
  18. }
複製代碼

TOP

返回列表