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

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;

}

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.
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) {}
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
Topic archived. No new replies allowed.