On 18 Jul 2007, at 12:05, Matthew Borgeson wrote: > Hey All- > > I just started attempting to program in Ruby a month ago, but have > reached > an impasse. > > I am writing a dosing program and am trying to do something very > simple: > Have a user enter either m for a male or f for a female so that > info can be > taken to the next equation to be used for something else. > > I originally wrote it as follows: > > #Introduction > > puts 'Hello. Welcome to the Aminoglycoside Dosing Calculator.' > # Determines the patient dosing gender > > puts 'What gender is your patient? Please enter m or f' > ptSexS = gets.chomp.downcase > if ptSexS == 'f' > doseSexS = 'female' > elsif ptSexS == 'm' > doseSexS = 'male' > end > puts 'Your patient is a ' + doseSexS > > > The problem here is I have written all of the mathematical > operations I need > in blocks like this, but I dont know how to make them accomodate > for invalid > answers. > For instance, if the user enters an m or an f above, I have the > doseSexS > determined for the next part of the program. If the user enters > something > else, I want it to ay "please try again' and start over.. > > I have tried while loops but cant get it to work as well as making > it into a > method. Is there a different way to do this that my lack of > experience is > preventingme from seeing/ Is iteration over a an array something worth > following? I apologize for such a basic question, but the > PickAxe,the book > by Chris Pine, and multiple web sites are failing me and I am > turnig here as > a last resort... > > Thanks in advance for any help > > Matthew F Borgeson > > > > You might try looking at using either raise ... rescue or throw ... catch to deal with errors. Discussion on p 360 of pickaxe and elsewhere. in your code something like if f elsif m else raise end with rescue elsewhere to do what you want with the error. Hope this helps. allbests,