re:your arrays are..

by Matt (no login)

Thank you, i hadn't realized that I had even done that. As for the issue with not placing the first name from the waiting list into the seating array, after fixing the IF statements the problem is gone.

Strange thing is.. Not what I have fixed the IF statements, I am having trouble printing the array when it is full. I have isolated both the waitlist() sub and the seating() sub as a menu option (for easier testing) by pressing either "4" or "5" in the menu screen. Seems like when the SEAT() array is full during normal operation it redirects you to wlist() as it should. But, when you go to view seat() array after entering names into the wlist() array, the seat() array will not print.

I have tried this by filling up the seat() array using the addpass() sub and by using the waitlist() sub repeatedly to fill up the list. Both produce the same result.

I suspect that it is something to do with the DO statement in the seating() sub.
Any idea?

Here is my code as of now.

SCREEN 12
DIM SEAT(10, 4) AS STRING
DIM WLIST(10) AS STRING
DIM MENU AS STRING

DECLARE SUB SEATING()
DECLARE SUB ADDPASS()
DECLARE SUB REMOVEPASS()
DECLARE SUB WAITLIST()

' **** MENU ****
DO
CLS
COLOR 15
PRINT "MAIN MENU"
PRINT
COLOR 7

PRINT "1) Add passenger to flight or waiting list"
PRINT "2) Remove passenger from flight"
PRINT "3) Exit"
PRINT
PRINT "Make a selection: ";
DO
MENU = INKEY$
SELECT CASE MENU
CASE "1" TO "5": EXIT DO
END SELECT
LOOP

SELECT CASE MENU
CASE "1": ADDPASS 'sub
CASE "2": REMOVEPASS 'sub
CASE "3": EXIT DO
CASE "4": WAITLIST 'sub
CASE "5": SEATING 'sub
END SELECT
LOOP
END

' **** SEATING ARRAY ****
SUB SEATING ()
SHARED WLIST() AS STRING
SHARED SEAT() AS STRING
DIM R AS INTEGER
DIM S AS INTEGER
DIM FOUND AS INTEGER

CLS

'checks for names in waitlist
'and adds them to the array
DO
FOUND = 0
FOR R = 1 TO 10
FOR S = 1 TO 4
IF SEAT(R, S) = "" THEN
SEAT(R, S) = WLIST(FOUND)
FOUND = FOUND + 1
IF FOUND > 10 THEN EXIT DO
END IF
NEXT S
NEXT R
LOOP WHILE FOUND <= 10

PRINT "SEATING LIST"

'adds labels to the top of array
PRINT TAB(13); "SEAT '1'"; TAB(27); "SEAT '2'"; TAB(43); "SEAT '3'"; TAB(58); "SEAT '4'"
PRINT

'adds labels to the left margin of array
FOR R = 1 TO 10
IF R = 1 THEN PRINT "ROW 1 ",
IF R = 2 THEN PRINT "ROW 2 ",
IF R = 3 THEN PRINT "ROW 3 ",
IF R = 4 THEN PRINT "ROW 4 ",
IF R = 5 THEN PRINT "ROW 5 ",
IF R = 6 THEN PRINT "ROW 6 ",
IF R = 7 THEN PRINT "ROW 7 ",
IF R = 8 THEN PRINT "ROW 8 ",
IF R = 9 THEN PRINT "ROW 9 ",
IF R = 10 THEN PRINT "ROW 10 ",

FOR S = 1 TO 4
PRINT SEAT(R, S) + "", 'prints array
NEXT S
NEXT R
SLEEP
END SUB

' **** ADD PASSENGER ****
SUB ADDPASS
SHARED SEAT() AS STRING
DIM NM AS STRING
DIM S AS INTEGER
DIM R AS INTEGER
DIM A AS STRING
DIM YN AS STRING
DIM FOUND AS INTEGER

CALL SEATING
PRINT
DO
'checks to make sure the array isn't full
'if array is full sends to waitlist
DO
FOUND = 0
FOR R = 1 TO 10
FOR S = 1 TO 4
IF SEAT(R, S) = "" THEN FOUND = 1
NEXT S
NEXT R
IF FOUND = 0 THEN
PRINT "There are no seats available."
INPUT "Would you like to add your name to the waiting list(y/n)"; YN
IF UCASE$(YN) = "Y" THEN
WAITLIST
EXIT DO
IF UCASE$(YN) = "N" THEN EXIT DO
END IF
END IF
LOOP WHILE FOUND = 0

'passenger name input
INPUT "Enter passenger name (blank to exit): ", NM
IF LEN(NM) = 0 THEN EXIT SUB

'seat selection input
INPUT "Enter seat number: (Row, Seat)", R, S

'makes sure the seat is available
'if available name is added to seat
IF SEAT(R, S) <> "" THEN
PRINT "That seat is not available."
ELSEIF SEAT(R, S) = "" THEN
SEAT(R, S) = NM
END IF

PRINT "Would you like to select another seat? (Y/N)"

'for option (y/n) input
DO
A = UCASE$(INKEY$)
LOOP UNTIL A = "Y" OR A = "N"
LOOP UNTIL A = "N"
CALL SEATING
PRINT
PRINT "Press any key to retern to menu"
SLEEP
END SUB

' **** REMOVE PASSENGER ****
SUB REMOVEPASS
SHARED SEAT() AS STRING
DIM NM AS STRING
DIM FOUND AS INTEGER


CLS
PRINT
CALL SEATING 'prints seating array

'passenger name input
DO
PRINT
INPUT "Enter passenger name (blank to exit): ", NM
IF LEN(NM) = 0 THEN
EXIT SUB
END IF

FOUND = 0
FOR R = 1 TO 10
FOR S = 1 TO 4

'searches for name and removes
IF UCASE$(NM) = UCASE$(SEAT(R, S)) THEN
FOUND = 1
SEAT(R, S) = ""
PRINT
PRINT "'" + NM + "'" + " was found and removed from the list."
EXIT FOR
PRINT
END IF
NEXT S
NEXT R

'if name was not found notifies
IF FOUND = 0 THEN
PRINT
PRINT "'" + NM + "'" + " was not found on the list."
PRINT
END IF
LOOP
END SUB

' **** WAITING LIST ****
SUB WAITLIST
SHARED WLIST() AS STRING
DIM X AS INTEGER
DIM FOUND AS INTEGER

CLS
PRINT
'passenger name input
DO
FOR X = 1 TO 10
INPUT "Enter passenger name (blank to exit): ", WLIST(X)
IF LEN(WLIST(X)) = 0 THEN EXIT DO
NEXT X
LOOP UNTIL X = 11
PRINT
FOR X = 1 TO 10
PRINT X; WLIST(X)
NEXT X
SLEEP
END SUB

Posted on May 22, 2012, 10:03 AM

Respond to this message   

Return to Index


Response TitleAuthor and Date
Re: CorrectionMATT on May 22
Sub can call other subs.Solitaire on May 22
 re: Sub can call..Matt on May 28