working with visual studios help.

My code is not recognizing cout and endl; Oh and my random numbers keep coming in as 1 or 0. Note sure why? Any help would be greatly appreciated.

1
2
3
4
5
6
7
#include <iostream>
#include <cstdlib>
#include <math.h>
#include <time.h>
#include <iomanip>

using namespace std;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int Random::poissonRandom(double expected)
{
  int n=0;
  double limit;
  double x;

  limit = exp(-expected);
  x = rand()/((double)RAND_MAX+1);
  while (x>limit)
    {
      n++;
      x *= rand()/((double)RAND_MAX+1);
    }
  return n;
}


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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*****************************************************************
* does everything pretty much
*******************************************************************/
int main(int argc, char* argv[])
{

}
   srand(2500);
   // FIX FIX FIX FIX use poisson distribution from above instead
   Random random;

   int endtime = 0;
   int lrefused = 0;
   int trefused = 0;
   int idle = 0;
   int planesLand = 0;
   int planesTakeOff = 0;
   int time = 0;
   int planeNum = 0;
   double arrivalsPerTime = 0;
   double takeOffsPerTime = 0;

   cout << "Units of time the simulation will run: ";
   cin >> endtime;
   cout << "Expected number of arrivals per time unit: ";
   cin >> arrivalsPerTime;
   cout << "Expected number of take offs per time unit: ";
   cin >> takeOffsPerTime;

   Queue takeOffQueue(5);
   Queue landQueue(5);
   int randnumber1, randnumber2;
   randnumber1 = random.poissonRandom(arrivalsPerTime);
   randnumber2 = random.poissonRandom(takeOffsPerTime);
   cout << randnumber1 << "   " << randnumber2 << endl;
   
   for (int curtime = 1; curtime < endtime; curtime++)
   {

      for (int i = 0; i < randnumber1; i++) // plane to land
      {
         planeNum = i;
         if (landQueue.full())// landing queue is full
         {
            // refuse plane to land
            lrefused++;
            cerr << "refused";
         }
         else
         {
            landQueue.insert(planeNum);
            // add plane to landing queue
            planesLand++;
            cerr << "plane landed: ";
         }
      }

      for (int i = 0; i < randnumber2; i++)
      {
         planeNum = i;//  create new plane

         if(takeOffQueue.full()) //takeoff queue is full
         {
            trefused++; //  refuse plane to takeoff
         }
         else
         {
            takeOffQueue.insert(planeNum);
            //  add plane to takeoff queue
         }
      }
      if (!landQueue.empty()) // landing queue is not empty
      {
         landQueue.remove();
         // land next plane in landing queue
		       }
      else if (!takeOffQueue.empty()) // takeoff queue is not empty
      {
         takeOffQueue.remove();
         // allow next plane in takeoff queue to takeoff
         planesTakeOff++;
      }
      else
      {
         idle++;
         // runway idle

      }
   }
   int numOfPlanes = randnumber1 + randnumber2;
   int readyLand = (landQueue.getBack() - landQueue.getFront());
   int readyTakeOff = (takeOffQueue.getBack() - takeOffQueue.getFront());
   cout << endl << endl;
   cout << "Total number of planes processed: 90       "       << endtime - (lr\efused + trefused) << endl;
   cout << "Number of planes landed:          50       "       << planesLand << endl;
   cout << "Number of planes taken off:       36       "       << planesTakeOff << endl;
   cout << "Number left ready to land:         0       "       << readyLand  << endl;
   cout << "Number left ready to take off:     0       "       << readyTakeOff  << endl;
   cout << "Number of planes refused use:      4       "       << lrefused + trefused << endl;
   cout << "Percentage of time runway idle:   14.00%   "       << idle / endtime << endl;
   cout << "Average wait time to land:         0.56    "       << idle * randnumber1  << endl;
   cout << "Average wait time to take off:     4.06    "       << idle * randnumber2 << endl;
   return 0;
}
There seems to be an extra closing brace at line 7, is this in your original code?
That solved the cout and endl problem. Thank you very much. As for the random number I'm still getting 0 and 1 for value.
Not sure why that is, I used your code for poisson distribution and it gives me different values. Check to make sure that the arguments are sensible when you call the function (print arrivalsPerTime and takeOffsPerTime after they are input)
Last edited on
Topic archived. No new replies allowed.