[Last Call] Learn how to a build a cloud-first strategyRegister Now


Using an array

Posted on 2006-03-25
Medium Priority
Last Modified: 2010-04-15
I want to use an array that will tell me which doors are open at the end of an experiment.  The experiment involves 100 students (who are numbered 1 through 100) and 100 doors (also numbered 1 through 100).  All doors begin as closed, but become open when a student goes through.  The students go through all doors that are multiples of their given number.
My first step would be to set up an array of 100 integers, but then how do I change their values of the array in multiples of the student's numbers?
Question by:yumaslim
LVL 14

Accepted Solution

cwwkie earned 100 total points
ID: 16287540
If your platform supports a boolean type, it is better to use that, but an array of 100 integers if fine. Let's say 0 means the door is closed, and 1 means the door is open.

You first need to set all doors to closed

Then you loop through all students, and you let each student open the doors based on their number.

At the end you check which doors are still closed.

Just try to start with this, and post the code when you're stuck.

Author Comment

ID: 16287561
How would I change the values of the doors based upon the student's number?  That's really where I'm getting stuck right now.
LVL 14

Expert Comment

ID: 16287613
Maybe use an enum for the doors;

typedef enum {DoorClose, DoorOpen} DoorState;
DoorState Doors[100];

To close a door, you do
to open a door:

But post the code you have so far, so we can take a look at it.
Take a look here for some hints to get started http:Q_21676313.html

Expert Comment

by:deepu chandran
ID: 16288158
hi friend,
   you can solve this through parallal array concept.i think u are expecting a logic like that

you can this using the following arrays,

DoorState Doors[100];
DoorStatus DS[100];

you can use cwwkie's logic along with this.

LVL 16

Assisted Solution

PaulCaswell earned 100 total points
ID: 16288179
Hi yumaslim,

Say a student has number 2. You must therefore set doors 2, 4, 6, ... to open. Use a loop starting at 2 and stepping by 2 each time until you reach 100.

Sorry we cant actually give you the code as this is a homework question.


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question