Else if, If and Else Blocks

Hi.
I'm trying to write a simulator for a supermarket, where customers are read into a queue, they line up, and then they are checked out at the register. Each customer comes with 3 types of data. Name, Number of items, and time arrived. The amount of time they take to check out is equal to the number of items, and then amount of time they have to wait in the line does NOT include the time they spent at the register.

So I use first an array to store the test data, then when the current time is equal to time arrived for a customer, then I read 1 element from the array into the queue. Max time is stored from when the information is being read from the test file into the array.

However, my code does not print anything out and I can't for the life of me figure out why. I have not included everything here, so please ask if you don't know what a function does, or what a variable stands for.

Front returns the head of a queue, remove removes the head of a queue without returning it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
void Supermarket :: Minimart()

{

  //c_time= current time
  //s_time is service time (amount of time they have been at the register)
  //i=the nth element in the shopping array

  Queue one;
  int c_time=0;
  int i=0;
  int s_time=0;
  
  //Adds the customers from the shopping array to the queue
  while(c_time<max_time)
  {  
     if(one.empty())
    { 
      c_time++;
      cout<<"else statement EMPTY"<<endl;
    }
    
    if(shopping[i]->gettime()==c_time)
    
    {
      one.add(shopping[i]);
      i++;
      cout<<"Added a customer"<<endl;   
    }
    
    
   if(!one.empty())
    {
      if(s_time==one.front()->getitems())
      {        
        cout<<"else statement FOUND"<<endl;
        cout<<one.front()->getname()<<" ";
        cout<<one.front()->getitems()<<" ";
        cout<<one.front()->gettime()<<" ";
        cout<<c_time-one.front()->gettime()-s_time<<endl;
        one.remove();
        s_time=0;
        if(!one.empty())
        {
          c_time++;
          s_time++;
        }
        else
        {
          c_time++;
        }
      }
    } 
    else 
    {
      if(!one.empty())
      {
        c_time++;
        s_time++;
      }
      else
      {
        c_time++;
      }
    }
    
  }  
}
Last edited on
Could you please indent the code? You'll want to wrap it in [code][/code] tags.
I've indented it, thanks
Topic archived. No new replies allowed.