[Solved] C Program Switch and If statement


You’re missing crucial break statements in your switch, e.g.

switch(rank)
{
  case 14:
   {
   if(suite == 'H')
        printf("Your card is the Ace of Hearts!");
   else if(suite == 'C')
        printf("Your card is the Ace of Clubs!");
   else if(suite == 'D')
        printf("Your card is the Ace of Diamonds!");
   else
        printf("Your card is the Ace of Spades!");
   }
  // <<< NB: case 14 "falls through" to case 13 here !!!
  case 13:
    ...

Change this to:

switch(rank)
{
  case 14:
   {
   if(suite == 'H')
        printf("Your card is the Ace of Hearts!");
   else if(suite == 'C')
        printf("Your card is the Ace of Clubs!");
   else if(suite == 'D')
        printf("Your card is the Ace of Diamonds!");
   else
        printf("Your card is the Ace of Spades!");
   }
   break; // <<< FIX
  case 13:
    ...

Repeat for all the other missing break statements.

solved C Program Switch and If statement