Hi all,
I am beginner C Programmer and am working on a simple program. My issue is to get it repeat by typing in "y" after it has me made its initial run. I am familiar with loops and have tried "do, while" in numerous combinations but I have no luck in getting it to repeat after it is initially done. Here is my code without loops, any help would be GREATLY appreciated:
Code:
#include <stdio.h>
int main()
{
char play;
char choice;
printf("Welcome to Two doors.\n");
printf("Would you like to play? (y/n): ");
scanf("%c", &play);
if (play == 'y')
{
printf("You are a prisoner in a room with 2 doors and 2 guards.\n");
printf("One of the doors will guide you to freedom and behind the other is a hangman --you don't know which is which.\n");
printf("One of the guards always tells the truth and the other always lies. You don't know which one is the truth-teller or the liar either.\n");
printf("You have to choose and open one of these doors, but you can only ask a single question to one of the guards.\n");
printf("What do you ask so you can pick the door to freedom?\n");
printf("\tA.Ask the truth-guard to point to the door of doom.\n");
printf("\tB.Ask the liar-guard to point to the door of doom.\n");
printf("\tC.Doesn't matter which one you pick.\n");
scanf("%s", &choice);
char answer;
printf("No matter which one you choose the guards both tell you which door leads to death, and therefore you can pick the other door.\n");
switch (answer)
{
case 1:
printf("C");
break;
case 2:
printf("C");
break;
case 3:
printf("C");
break;
default:
break;
}
}
return 0;
}