I have an IF-statement that I want to transform into a Switch-statement... But it has 2 variables! Is it possible to do it on C?
It is a rock, paper, scissors game:
#include
#include
#define PAIR(X,Y) (X<<8)|Y
int main()
{
char play1, play2;
printf("\nPlayer 1 - Enter your Play: ");
scanf ("%c", &play1);
printf("\nPlayer 2 - Enter your play: ");
scanf (" %c", &play2);
switch (PAIR(play1, play2)) {
case PAIR('R','P'):
printf ("Paper wins!\n");
break;
case PAIR('R','S'):
printf ("Rock wins!\n");
break;
case PAIR('R','R'):
printf ("Draw!\n");
break;
default: //any thing else
printf ("Default!\n");
break;
}
}