1 2 3 4 5
|
Reservation::Reservation()
{
seats = 10;
plane[seats] = { 0 };
}
|
out of bounds access.
that's not the way to initialise an array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
int Reservation::reserveSmoking(int num)
{
for (int i = 0; i < seats; i++) {
cout << "Please select from one(0) to four(4): ";
cin >> num;
while (num <0 ||num >4) {
cout << "Please select from one(0) to four(4): ";
cin >> num;
}
reduceAvailableSeats();
if (plane[i] == i) { //¿what?
return num;
}
else {
i++; //¿how many times do you want to increase i?
}
}
return -1;
}
|
you ignore the parameter
try to do all input/output operations on main()
¿where do you ever set `plane' values?
same errors in nonSmoking, besides a bad copy-paste
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int Reservation::reserveRandomNonSmoking()
{
for (int i = 0; i < seats; i++) {
srand(time(0));
seats = 6 + rand() % 5;
if (plane[i] == i) {
return seats;
}
else {
i = i + 1;
}
}
return 0;
}
|
same errors as before.
¿how many meanings does `seats' have?
you use it as the limit on the loop and also to get a random number
srand() should be called just one time in your entire program
1 2 3 4
|
void Reservation::reduceAvailableSeats()
{ while(seats<=0)
seats--;
}
|
get pen an paper and simulate that function
try with seats equal to 5, 1, and 0
Also, ¿don't you realise that your code for smoking is almost the same as for nonsmoking?
¿doesn't that tingle your vinyl antennas?