Click to See Complete Forum and Search --> : Airline seating problem


Carcophan
12-17-2004, 04:03 PM
I am sure many of you have seen the 'Airline seating reservation' assignment that C++ classes give out. I would like to state that I am NOT asking people to do it for me, although I am having a problem getting it to work properly and would greatly appreciate some help.

For those of you who don't know the assignment is... "A small airline company has one 10 seat plane and needs a reservation system. The program should use a menu display to decide if the customer wants economy or first class seating (1-5 for FC, 6-10 for eco). The program needs to print a boarding pass with the assigned section and seat in it. Use a single-subscripted array to represent the seating chart and initialize each seat to 0 to indicate that the seat is empty. Program shouldnt assign a seat that is taken blah blah...but when a section is full the program should ask if a seat in the opposing section is okay and assign that, if they choose no or both sections are full the program should suggest taking the next flight."

That said...my problem is:
I can get the program to recognize that the first class section is full when it gets full and it promts the user to either take a economy seat or take the next flight. BUT when the economy section is full it doesnt suggest First class or the next flight. It does stop counting seats at 10, but once at 10 it just keeps asking if I would like to reserve another FC seat econo seat or -1 to end. The code for both first class and econmy should pretty much be the same and I simple can not see why it doesnt work right.

I'm not sure if i should post all the code here, incase other students are here, I dont want to do there project for them, but I would be more then happy to email it to you. Any help would be appreciated and it is due monday so i'm in a bit of a bind.

Thanks.

jonnin
12-17-2004, 06:32 PM
Your problem is probably a slightly bad logic error; for example you may have it test if fc is full, and if so do whatever, and then your test for the if normal is full is accidentally inside the first class one or something. Its a simple logic error and the only way to find it is to debug it. First pass is to look for

if(somthing); <--- oops! ; makes a problem!
or messed up brackets


Debugging can be done with the build in debugger (add watches to all variables and step in it)
or by printing the thing and playing computer (not too useful on larger projects, but it can help)
or adding print statements of this form:
cout << "I got here #1 "<< write any important value etc;

Carcophan
12-17-2004, 07:37 PM
I figured it out :rolleyes:

I had 2 while loops, on with while(i < 10) and while(j <10)...both should have been i becuase both while loops were using the same 10 elements.

And printing it actually helped me notice that, thanks jonnin.

jonnin
12-18-2004, 01:07 AM
no problem =)
Someone asked why I don't like the i j notation, and one of the reasons is both are dotted sticks, some fonts are far to close for comfort. I hate slavery to convention... take u v subs in calculus... most math professors can't write u and v distinctly, but they refuse to make it like P and M or something you can tell apart, because its always been u and v. *shakes his fist*
I feel better now...