Rewrite the following code using if statements using C. #include <stdio.h> #incl
ID: 3557946 • Letter: R
Question
Rewrite the following code using if statements using C.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int input;
do
{
printf( "1. Play game " );
printf( "2. Load game " );
printf( "3. Play multiplayer " );
printf( "4. Exit " );
printf( "Selection: " );
scanf( "%d", &input );
switch ( input )
{
case 1:
printf("Playing the game ");
break;
case 2:
printf("Loading the game ");
break;
case 3:
printf("Playing multiplayer ");
break;
case 4:
printf( "Thanks for playing! " );
break;
default:
printf( "Bad input! " );
break;
}
} while(input != 4);
system(
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
int main()
{
int input;
do
{
printf( "1. Play game " );
printf( "2. Load game " );
printf( "3. Play multiplayer " );
printf( "4. Exit " );
printf( "Selection: " );
scanf( "%d", &input );
if(input==1)
printf("Playing the game ");
else if(input==2)
printf("Loading the game ");
else if (input==3)
printf("Playing multiplayer ");
else if(input==4)
printf( "Thanks for playing! " );
else
printf( "Bad input! " );
} while(input != 4);
system(
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.