Ruby: airline reservation (arrays)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hugg
    New Member
    • Oct 2011
    • 1

    Ruby: airline reservation (arrays)

    I cannot, for the life of me and my goldfish, get this code to work for an assignment. I cannot make it change the array location to a 1 to make it "filled" by a passenger. I do .inspect at the end of the script and the array is just full of 0's (like how it is already set up), nothing I have tried will get the array to reflect what I want it to do.

    What am I doing wrong?

    The boolean array is called $assignment. Coach is $c and First class is $f. $i is the counter to keep track of where the 0's and 1's are in the array (I think, at least that's what I want it to do). First class is seats 1-5 and Coach is 6-20.


    Code:
    loop do
        puts "If you'd like to fly in first class, Press [1]. If you'd like to fly coach, Push [2]."
        answer = STDIN.gets
        answer.chop!
        break if answer =~ /1|2/
       
        if answer == 1 #User wants FIRST class
        $first = (0..4).find { |i| $available[i] != 1 } # Change display of open seats, first class.
          answer == 1
         $i += 2 #Trying to swap 0 to 1 for 1st class
         $available[$i] += 1
    
    end
        if answer == 2 #User wants COACH
         $coach = (5..19).find { |i| $available[i] != 1 } #Seat 6 thru 20 COACH
          answer == 2
          $i += 2 #Trying to swap 0 to 1 for COACH seats.
          $available[$i += 5]
          if nil then
            puts "FULL! Coach"
         if answer.length > 1
           puts "Nothing over 1 digit!"
           redo
        else
          puts "Invalid number, enter 1 or 2."
          Console_Screen.pause
         end
    end
Working...