I was thinking of the for loop at the end to show the final doors that remain open, and that would be sufficient.
Do you want to show the status of the doors, as they change? Little text based display to represent the doors?
This is a little tricky, because you have to use the index of the doors array, in an entirely new manner (for you). Post up your code and let's see where you are at.
Don't make fun of me because of how off I am please :/Code:
It still looks like you're throwing code at the problem and hoping something will stick.
The first thing you need to do, even before opening and shutting various doors, is decide how you are going to represent the doors. How do you tell the difference between an open door and a closed one?
Actually you're not that far off at all... based on what you've posted, you mostly need to devise a way to make the door change, which you aren't doing yet... the loops are pretty close though.
I don't mean to lecture... but what is happening now is that analysis phase I discussed earlier, except you're doing it with live code... yes it can be done that way but it's not always the smartest way to do it since you can easily "code yourself into a corner". The bigger the job the more likely that becomes. (And yes, I've done it to myself moe than once.)
As far as figuring out which doors are doing what I can't seem to get anywhere close to making it work. I was think that you could have some sort of system that says 0 for closed doors and 1 for open doors, at the end print all the doors with a 1. I can't figure out how to implement that though.
Ok, here's a hint... the door starts out closed... a student goes through and it's open... a student goes through and it closes... student open... student closed... see a pattern? What happens every second time? What is every second number?
#define Open 1
I agree, I thought it added to the clarity of the whole thing.
You need to swap your for loops. Put the studentNumbers on the outer for loop, and the door logic, inside the nested for loop. You don't need the third for loop, until you're ready to print the final status.
I would change your doors array size to 101, and set the value of each element of that array, to 0, instead of i. Start your for loops at 1, and stop at <= 100, instead of just < 100.
That will initialize all the doors starting to closed. (what I would call closed, anyway).
While it's undoubtedly true, a simple if() statement will handle that door open or door closed action.
you want s*n, but you need it as the index for the doors.
That's the hardest thing about this problem, imo.
Ignore the comment about the third for loop. Your code threw me off a bit.
Your index for the doors array needs to be a multiple of studentNumber * a multiplier, in the inner for loop.
You can use just doors[studentNumber * n] = Open or 1 or Closed or 0.
Check out the pattern:
Student number is 3:
3 * 1 first door he visits -- n equals 1
3 * 2 second door he visits-n equals 2
3 * 3 third door he visits, etc.
3 * 4 fourth door he visits