Here's your own code properly indented :
//indented code
#include<iostream>
#include<time>
#include<stdlib>
#include<stdio>
using namespace std;
struct node
{
node *next;
long time_start,time_total,time_compare;
};
class queue
{
private:
node *head;
node *tail;
node n;
long time_global;
public:
int count;
queue();
void addnode();
void print();
void dequeue();
friend int choose_counter(queue&,queue&,queue&,queue&);
friend int choose_counter1(queue&,queue&,queue&);
};
queue::queue()
{
head=NULL;
tail=NULL;
count=0;
time_global=time(NULL);
}
void queue::addnode()
{
if(head==NULL && tail==NULL)
{
node *person=new node;
tail->next=NULL;
time_compare=time(NULL)+rand()%10;
count++;
}
else
{
node *person=new node;
tail->next=person;
tail=tail->next;
tail->next=NULL:
count++;
}
if (head->time_compare==time_global)
dequeue();
}
void queue::print()
{
cout<<"STATUS OF QUEUES:"<<endl;
}
void queue::dequeue()
{
node *temp;
temp=head;
head=head->next;
count--;
if(count==0)
head=tail=NULL;
else
{
srand(time(NULL));
head->time_compare=time(NULL)+rand()%10;
head->time_total=time_compare-time_start;
}
}
int main()
{
queue q1,q2,q3,q4;
char choice;
cout<<"PLEASE CHOSE FROM THE FOLLOWING MENU:"<<endl
<<endl<<"1. To enter a male customer, press 'M'."
<<endl<<"2. To enter a female customer, press 'F'."
<<endl<<"3. To exit press 'X'."<<endl;
cin>>choice;
switch(choice)
{
case 'M':
{
int c=choose_counter(q1,q2,q3,q4);
if(c==0)
q1.addnode();
else if(c==1)
q2.addnode();
else if(c==2)
q3.addnode();
else if(c==3)
q4.addnode();
else
int d=choose_counter1(q1,q2,q3);
if (d=1)
q1.addnode();
else if(d=2)
q2.addnode();
else
q3.addnode();
}
break;
}
case 'F':
{
int c=choose_counter(q4,q2,q3,q1);
if(c==0)
q4.addnode();
else if(c==1)
q2.addnode();
else if(c==2)
q3.addnode();
else if(c==3)
q1.addnode();
else
q4.addnode();
break;
}
case 'X':
{
exit(0);
}
}
return 0;
}
int choose_counter(queue& obj1,queue& obj2,queue& obj3,queue& obj4)
{
if(obj1.head==NULL)
return 0;
else if(obj2.head==NULL)
return 1;
else if(obj3.head==NULL)
return 2;
else if(obj4.head==NULL)
return 3;
else
return 5;
}
int choose_counter1(queue& obj1,queue& obj2,queue& obj3)
{
if(obj1.count<obj2.count && obj2.count<obj3.count)
return 1;
else if(obj2.count<obj1.count && obj2.count<obj3.count)
return 2;
else
return 3;
}
There are quite a lot of things wrong with this code:
It's starts with your include files:
#include<iostream>
#include<time>
#include<stdlib>
#include<stdio>
Change it to:
#include<iostream>
#include<ctime>
#include<stdlib.h>
#include<stdio.h>
line 125-129, you have an extra bracket
else
q3.addnode();
} <--- delete this one
break;
}
line 121-123
if (d=1)
q1.addnode();
else if(d=2)
I guess you meant == instead of =? Remember: = != ==.
And where did the 'd' come from? It's never delcared?
Line 52:
time_compare=time(NULL)+rand()%10;
time_compare is never declared
line 60:
tail->next=NULL: <-- change this : to a ;
line 86-90:
{
srand(time(NULL));
head->time_compare=time(NULL)+rand()%10;
head->time_total=time_compare-time_start;
}
time_compare and time_start are never declared
etc. You should first get this to compile. Look careful at the compiler-errors and warning you get and try to fix it one problem at a time.
Good luck!