Thread: 100 doors 100 students help

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    6

    100 doors 100 students help

    I'm trying to make a simple code for this problem: There are 100 doors (numbered 1 through 100) and 100 students (numbered 1 through 100) waiting in a line. Initially, all the doors are open. A student numbered x passes through all the doors that are multiples of x (i.e., student numbered x goes to doors x; 2x; 3x; ... ) and changes the status of each door, i.e., opens the door if it is closed and closes the door if it is open. After all the students complete their turns, which doors remain open?

    anyway here is my code for it:

    Code:
    #include<stdio.h>
    
    
    int main(void) {
        int door = 1;
        int student = 1;
        int check;
        int counter = 0;
        int open = 0;
        int check2;
        
        for (door ; door <= 100 ; door++) 
        {
    
    
            for (student = 1;  student <= door ; student++)
            {
                check = (door % student);
                if (check = 0)
                {
                    counter = counter + 1;
                    printf("321");
                }
            }
            check2 = counter % 2;
            if (check2 = 0)
            {
                open = open + 1;
                printf("123");
            }
        }
        printf(" %d ", open);
    }
    the code never seems to enter the if statements which is clearly a problem. I just don't know what went wrong with this. Any help would be very appreciated/

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    if (check = 0) this is assignment
    you want
    Code:
    if (check == 0)
    Also you need to have an array of 100 doors to store the status of the door

    Kurt

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    6
    I knew it had to be something silly like that. Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening doors game
    By green_ghoul in forum C Programming
    Replies: 6
    Last Post: 11-09-2011, 05:02 PM
  2. need help with sorting students GPA
    By cprogisfun in forum C Programming
    Replies: 7
    Last Post: 12-10-2010, 06:14 AM
  3. Doors in a raycasting engine
    By lmaster in forum Game Programming
    Replies: 3
    Last Post: 06-09-2004, 11:57 PM
  4. Any Computeach International Students/ex students??
    By stevey in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 03-26-2002, 04:12 PM