need assistance

ok i am working on an elevator system and i am stuck... in the arrival method i am trying to get 400 workers to arrive within 3600 seconds... doing this
1
2
3
4
5
6
7
8
9
10
void Worker::Arrived()
{
	if (Seconds = 0 && Seconds != 3600)
	{
		if (WorkerCount = 0 && WorkerCount != 400)
		{
			WorkerCount++;
		}
	}
}

will give me only 400 workers but it will do it in 400 seconds... i need to span it out... is there a way to do it?
You do realise that you need two '=' signs for a comparison? The WorkerCount++; statement will never be executed the way you have it. You probably also wanted '||' instead of '&&' as well, but I'm not entirely sure what you are trying to do there...

As for spanning it out, just set the 'WorkerCount' related to the amount of seconds passed. So, you could do something like this:
1
2
3
void Worker::Arrived() {
    WorkerCount = (Seconds * 400) / 3600;
}


Alternately, if you know the function will be called every time the Seconds count is increased:
1
2
3
4
void Worker::Arrived() {
    if ((Seconds > 0) && (Seconds <= 3600) && (Seconds % (3600 / 400) == 0))
        ++WorkerCount;
}
Last edited on
apologies i generally forget about the == rule. but i did go back through my code and changed it thank you.. as for the information it is greatly appreciated. as far as
"You probably also wanted '||' instead of '&&' as well, but I'm not entirely sure what you are trying to do there..."

what would be the difference in the two operations???
'&&', or and, specifies that both conditions must be true. In your case, the statement succeeds if Seconds is 0 AND Seconds isn't 3600. If you look, though, if Seconds is 0 then it can't be 3600, can it? However, it also means that the statement will only succeed when Seconds is 0.

'||' is OR, so if either statement is true it will succeed. However, even then, you have irrelevant information...

In short, you can contract your current function to the following:
1
2
3
4
5
void Worker::Arrived() {
    if (Seconds == 0)
        if (WorkerCount == 0)
            ++WorkerCount;
}

Which presumably isn't what you want.
Last edited on
no it is definitely not thank you for clearing that up imma have to look through my other codes and see if i have that problem elseware... thank you for your help

ok i found something here

1
2
3
4
5
6
7
void Time::LunchEnd()
{
	Worker w;

	if (Seconds = 18900 && Seconds != 19800)
		w.Arrived();
}


so again i would have to use or correct or else seconds would be stuck at 18900??
Topic archived. No new replies allowed.