Hello everyone,
I am trying to calculate my arrivalscount and departurescount using a vector but my second loop isnt outputing any value. I think its because of my for loops......but I'm not sure. CAN I WRITE 2 FOR LOOPS TOGETHER?? Please advice>>>Thanks.
This is what I wrote in my main:
insert
Code:
int main()
{
srand(time(NULL));
Customers c;
c.generateBookings();
vector<Booking> a = c.getbooking();
c.generateBookings(0, 0, 0, 0, 0);
vector<Booking> b = c.getbooking();
for(int i=0; i < 10;i++)
{
cout << "Booking number " << i << ":" << endl;
cout << "booking: " << b[i].bookingTime << endl;
cout << "arrival: "<<b[i].arrivalTime << endl;
cout << "departure: "<<b[i].departureTime << endl;
}
int arrivalscount[10];
int totalarrivals = 0;
for(int i = 0; i < 10; i++)
{
arrivalscount[i] = 0;
for(int j = 0; j < a.size() - 1; j++)
{
if(a[j].arrivalTime >= i && a[j].arrivalTime < i + 1)
{
arrivalscount[i] += 1;
totalarrivals += 1;
}
}
}
for(int i = 0; i < 10; i++)
{
cout << "Interval [" << i << "," << i + 1 << ") arrivals: " << arrivalscount[i] << '\n';
}
cout << "Total arrivals = " << totalarrivals << '\n' ;
//*************************************************
int departurescount[10];
int totaldepartures = 0;
for (int i = 0; i < 10; i++)
{
departurescount[i] = 0;
for (int k = 0; k = a.size() - 1; k++)
{
if(a[k].departureTime >= i && a[k].departureTime < i + 1)
{
departurescount[i] += 1;
totaldepartures += 1;
}
}
}
for (int i = 0; i < 10; i++)
{
cout << "Interval [" << i << "," << i + 1 <<") departures: " << departurescount[i] << '\n';
}
cout << "Total departures = " << totaldepartures << '\n';