Advertisement
dmilicev

struct_card.c

Mar 15th, 2021
861
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     struct_card.c
  4.  
  5.     Task:
  6.     https://www.facebook.com/photo/?fbid=3002846189938230&set=gm.1845764445582397
  7.  
  8.     From Oona Lishanne Ismael
  9.     https://www.facebook.com/groups/177292205762971/user/100006386341873/
  10.  
  11.  
  12.     You can find all my C programs at Dragan Milicev's pastebin:
  13.  
  14.     https://pastebin.com/u/dmilicev
  15.  
  16. */
  17.  
  18. #include <stdio.h>
  19.  
  20. struct Card
  21. {
  22.    char suit;
  23.    int value;
  24. };
  25.  
  26. int main(void)
  27. {
  28.     struct Card c;
  29.  
  30.     while(1)
  31.     {
  32.         printf("\n Input card value [1-13]:  ");
  33.         scanf("%d", &c.value);
  34.  
  35.         if( c.value<1 || c.value>13 )
  36.             printf("\n Ivalid card value! \n");
  37.         else
  38.             break;
  39.     }
  40.  
  41.     while(1)
  42.     {
  43.         printf("\n Input card suit [C, D, H, S]:  ");
  44.         scanf(" %c", &c.suit);
  45.  
  46.         if( c.suit=='C' || c.suit=='c' ||
  47.             c.suit=='D' || c.suit=='d' ||
  48.             c.suit=='H' || c.suit=='h' ||
  49.             c.suit=='S' || c.suit=='s'   )
  50.             break;
  51.         else
  52.             printf("\n Ivalid card suit! \n");
  53.     }
  54.  
  55.     switch (c.value)
  56.     {
  57.         case 1:
  58.             printf("\n Ace ");
  59.             break;
  60.         case 2 ... 10:
  61.             printf("\n %d ", c.value);
  62.             break;
  63.         case 11:
  64.             printf("\n Jack ");
  65.             break;
  66.         case 12:
  67.             printf("\n Queen ");
  68.             break;
  69.         case 13:
  70.             printf("\n King ");
  71.             break;
  72.         default:
  73.             printf("\n Value out of range, error! \n");
  74.             break;
  75.     }
  76.  
  77.     switch (c.suit)
  78.     {
  79.         case 'C':
  80.         case 'c':
  81.             printf("of Clubs \n");
  82.             break;
  83.         case 'D':
  84.         case 'd':
  85.             printf("of Diamonds \n");
  86.             break;
  87.         case 'H':
  88.         case 'h':
  89.             printf("of Hearts \n");
  90.             break;
  91.         case 'S':
  92.         case 's':
  93.             printf("of Spades \n");
  94.             break;
  95.         default:
  96.             printf("\n Suit out of range, error! \n");
  97.             break;
  98.     }
  99.  
  100.     return 0;
  101.  
  102. } // main()
  103.  
Advertisement
RAW Paste Data Copied
Advertisement