473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Ruby: airline reservation (arrays)

1
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.


Expand|Select|Wrap|Line Numbers
  1. loop do
  2.     puts "If you'd like to fly in first class, Press [1]. If you'd like to fly coach, Push [2]."
  3.     answer = STDIN.gets
  4.     answer.chop!
  5.     break if answer =~ /1|2/
  6.  
  7.     if answer == 1 #User wants FIRST class
  8.     $first = (0..4).find { |i| $available[i] != 1 } # Change display of open seats, first class.
  9.       answer == 1
  10.      $i += 2 #Trying to swap 0 to 1 for 1st class
  11.      $available[$i] += 1
  12.  
  13. end
  14.     if answer == 2 #User wants COACH
  15.      $coach = (5..19).find { |i| $available[i] != 1 } #Seat 6 thru 20 COACH
  16.       answer == 2
  17.       $i += 2 #Trying to swap 0 to 1 for COACH seats.
  18.       $available[$i += 5]
  19.       if nil then
  20.         puts "FULL! Coach"
  21.      if answer.length > 1
  22.        puts "Nothing over 1 digit!"
  23.        redo
  24.     else
  25.       puts "Invalid number, enter 1 or 2."
  26.       Console_Screen.pause
  27.      end
  28. end
  29.  
Oct 20 '11 #1
0 2409

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Useko Netsumi | last post by:
or perhaps Java for developing web application? I've develop a few applications using PHP/MySQL/Apache and its growing in size. After reading the Ruby tutorial, and do a simple script, I kind of...
54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
1
by: hiboo | last post by:
Does anyone know of any open source java software/code libraries for doing travel/airline reservations? I'm looking for a typical airline (hotel, car rental?) reservation system. system in perl or...
7
by: meena76 | last post by:
I posted my problem in ref to my Airline Reservation Program. I am using VB 2005 for this program I have to right a program that req a users name for a text box then assigns the user a seat...
1
by: tabloidster | last post by:
Howdy All, I recall seeing a similar post a while back, but I'm not an expert VB programmer so I'm still not clear... For my VB6 class, I've got to code a basic reservation system. Let's say...
2
by: cotty | last post by:
AIRLINE RESERVATION SYSTEM A small airline has just purchased a computer for its new automated reservations system. The president has asked you to program the new system in C. You are to write a...
6
by: latalui | last post by:
A small airline has just purchased a computer for its new automated reservations system. You have been asked to program the new system. You are to write a program to assign seats on each flight of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.