qbasicstudent123
Technical User
Please help me with this problem. I am having a problem with my bubble sort. Here is the problem and what I have so far:
The Klingons have captured Spock, science officer of the U.S.S. Enterprise. Captain Kirk has broken into their prison colony to free him. He has reached the computer that possesses information concering all of the prisoners, including their cell numbers. Write a program to propmt the user to enter the following data into the program. The data should be stored in three parallel arrays:
Prisoner.....Ship...........Cell#
Kanobi.......Falcon.........328
Spock........Enterprise.....562
Yoda.........None...........122
Mudd.........Pleasure Dome..222
Khan.........Botany Bay.....009
Jetson.......Astrofly.......468
Rogers.......Galaxy 2.......727
Koenig.......Alpher.........999
Adama........Galactic.......987
Who..........Tardis.........585
The output should be alphabetized by name using a bubble sort.
This is what I now have:
CLS
DIM prisoner$(1 TO 10), ship$(1 TO 10), cell$(1 TO 10)
PRINT TAB(10); "This program will collect data on prisoner locations."
PRINT
PRINT
'*** Collecting data ***
FOR count = 1 TO 10
INPUT "Enter the prisoner's name: ", prisoner$(count)
PRINT
INPUT "Enter the ship that the prisoner is on: ", ship$(count)
PRINT
INPUT "Enter the cell that the prisoner is being held in: ", cell$(count)
PRINT
CALL dividingline
PRINT
NEXT count
' *** Sorting prisoner names in alphabetical order ***
final = 10
flag = 1
DO WHILE flag = 1
flag = 0
FOR count = 1 TO final
IF prisoner$(count) > prisoner$(count + 1) THEN
SWAP prisoner$(count), prisoner$(count + 1)
SWAP ship$(count), ship$(count + 1)
SWAP cell$(count), cell$(count + 1)
flag = 1
END IF
NEXT count
final = final - 1
LOOP
' *** Display Output ***
PRINT TAB(15); "Prisoner"; TAB(30); "Ship"; TAB(45); "Cell #"
CALL dividingline
FOR count = 1 TO 10
PRINT TAB(15); prisoner$(count); TAB(30); ship$(count); TAB(45); cell$(count)
NEXT count
SUB dividingline
PRINT "----------------------------------------------------------"
END SUB
After I enter all of the prisoners, the ship they are on, and the cell #'s, I get a "Subscript Out Of Range" error, and the "IF prisoner$(count) > prisoner$(count + 1) THEN" turns white. Any help would be greatly appreciated. Thank you.
The Klingons have captured Spock, science officer of the U.S.S. Enterprise. Captain Kirk has broken into their prison colony to free him. He has reached the computer that possesses information concering all of the prisoners, including their cell numbers. Write a program to propmt the user to enter the following data into the program. The data should be stored in three parallel arrays:
Prisoner.....Ship...........Cell#
Kanobi.......Falcon.........328
Spock........Enterprise.....562
Yoda.........None...........122
Mudd.........Pleasure Dome..222
Khan.........Botany Bay.....009
Jetson.......Astrofly.......468
Rogers.......Galaxy 2.......727
Koenig.......Alpher.........999
Adama........Galactic.......987
Who..........Tardis.........585
The output should be alphabetized by name using a bubble sort.
This is what I now have:
CLS
DIM prisoner$(1 TO 10), ship$(1 TO 10), cell$(1 TO 10)
PRINT TAB(10); "This program will collect data on prisoner locations."
'*** Collecting data ***
FOR count = 1 TO 10
INPUT "Enter the prisoner's name: ", prisoner$(count)
INPUT "Enter the ship that the prisoner is on: ", ship$(count)
INPUT "Enter the cell that the prisoner is being held in: ", cell$(count)
CALL dividingline
NEXT count
' *** Sorting prisoner names in alphabetical order ***
final = 10
flag = 1
DO WHILE flag = 1
flag = 0
FOR count = 1 TO final
IF prisoner$(count) > prisoner$(count + 1) THEN
SWAP prisoner$(count), prisoner$(count + 1)
SWAP ship$(count), ship$(count + 1)
SWAP cell$(count), cell$(count + 1)
flag = 1
END IF
NEXT count
final = final - 1
LOOP
' *** Display Output ***
PRINT TAB(15); "Prisoner"; TAB(30); "Ship"; TAB(45); "Cell #"
CALL dividingline
FOR count = 1 TO 10
PRINT TAB(15); prisoner$(count); TAB(30); ship$(count); TAB(45); cell$(count)
NEXT count
SUB dividingline
PRINT "----------------------------------------------------------"
END SUB
After I enter all of the prisoners, the ship they are on, and the cell #'s, I get a "Subscript Out Of Range" error, and the "IF prisoner$(count) > prisoner$(count + 1) THEN" turns white. Any help would be greatly appreciated. Thank you.