Firstly, I would get rid of the variable a, since it's global and never used.
Then I would write it like this to emphasize readability.
Code:
#include <stdio.h>
int main()
{
int c;
int key;
key = 0;
printf("\n\nYou stand before a locked door. There is a key nearby.\n\n");
printf("a. Take key.\nb. Open door.\n\n");
c = getch();
if (c == 'a')
{
printf("You take the key. What would you like to do now?\n\n");
key = 1;
printf("a. Open the door!\n");
printf("b. Examine the key.\n");
c = getch();
if (c == 'a' && key == 1) printf("You open the door...");
if (c == 'b' && key == 1) printf("It's a nice enough key, shiny and gold.");
}
if (c == 'b' && key == 0)
{
printf("You don't have the key.");
}
}
But this is not enough.
Consider these lines...
Code:
if (c == 'a' && key == 1) printf("You open the door...");
if (c == 'b' && key == 1) printf("It's a nice enough key, shiny and gold.");
Key is always set to 1! So there is no point in checking it here... unless, of course, you don't intend to always set it to 1.