[try Beta version]
Not logged in

 
Problem with my Queue coding >> if else and while loop

Aug 5, 2010 at 4:35pm
anyone can help to solve this ?

#include<queue>
#include<iostream>
#include<ctime>
using namespace std;

void wait (int seconds) //timer
{
clock_t ewait;
ewait = clock() + seconds * CLOCKS_PER_SEC;
while (clock() < ewait ) {}
}
/*
class Counter{
int count;
int waittime;
public:
Counter() : count(0) {}
Counter(int i) : count(waittime) {}
int operator()(){
return count++;
}
};*/


int main()
{
queue <int> Q;
queue <int> waitID;
int temp1, temp2;

int number, waittime, arrivetime, temp;
for (int i =0; i<5 ; i++)
{
number = 1+ rand() %10; // generate random ID
arrivetime = 1+ rand() %3; // generate random arriving time
waittime = 1 + rand() %16; // generate random serving time
cout <<"Job ID - "<< number << " ----- " << "Service time: " << waittime << "sec" <<endl;
wait(arrivetime);
Q.push(number);
waitID.push(waittime);
}

while (!Q.empty())
{
cout<<"Server 1 serving "<< Q.front() << " serving.. wait .."<< waitID.front() <<endl;

do
{
waitID.front()--;
cout<<"Sec left:"<<waitID.front()<<endl;
wait(1);
}

while(waitID.front()>1);
{
Q.pop();
waitID.pop();
cout <<" Job done "<<endl;
}
/*
while (waitID.front() == 7)
{
temp1 = Q.front(); // store into temp storage
temp2 = waitID.front();
Q.push(temp1);// push temp element to the queue
waitID.front()--;
waitID.push(temp2);

cout << "requeue" << temp1<<endl;
}
*/
}

if (waittime >= 7)
{
//Counter waitID.front();
//Counter();
temp1 = Q.front(); // store into temp storage
temp2 = waitID.front();
Q.push(temp1);// push temp element to the queue
waitID.front()--;
waitID.push(temp2);

cout << "requeue" << temp1 <<endl;
}
else if
{

}

cout << "No more queue" <<endl;

}

Aug 5, 2010 at 7:09pm
What do you want solved? If all you want to do is fix the errors include cstdlib so you can use rand and delete
1
2
3
4
else if
{

}
which starts at line 86. Also edit your post and add code tags.
Aug 5, 2010 at 9:55pm
1
2
3
4
5
while(condition);
{
    statement1;
    statement2;
}

Please don't do that, it's confusing.


I know it's commented but, what is this supposed to do?
Counter(int i) : count(waittime) {}
Aug 5, 2010 at 10:39pm
That's an constructor with an initializer list. However it seems odd in that it is assigning waittime (an uninitialized variable) to count, ignoring the passed value of i.
Last edited on Aug 5, 2010 at 10:40pm
Topic archived. No new replies allowed.