Thread: Changing a variable

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    8

    Changing a variable

    Hi. I'm trying to write a simple program where you need a key to open a door, and it requires you to get the key before opening the door. I'm getting some errors. This is what I have so far:


    Code:
    #include <stdio.h>
    #define KEY 0
    
    int a;
    
    int main() {
    
        char c;
        int key;
        key = 0;
    
        printf("You stand before a locked door. There is a key nearby.\n\n");
        printf("a. Take key.\nb. Open door.\n");
        
        c=getch();
        
        if(c == 'a')  {
            printf("\nYou take the key.\n"); 
        }
        key = 1; 
        
            
        if(c == 'b') && KEY = 0 {
            printf("\nYou do not have the key.\n"); 
            
        if(c == 'b') && KEY = 1 {
            printf("\nThe door unlocks with ease.\n"); 
            
        }
    }
    Sorry for asking such a basic question, but if anybody can help me with this code, I'll appreciate it.
    Last edited by matthew82; 02-05-2009 at 01:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to put a check on an extern variable set as flag
    By rebelsoul in forum C Programming
    Replies: 18
    Last Post: 05-25-2009, 03:13 AM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  3. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  4. write Variable and open Variable and get Information
    By cyberbjorn in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 01:30 AM
  5. Changing variable
    By Mithoric in forum Windows Programming
    Replies: 4
    Last Post: 03-30-2004, 09:45 PM