From: Andrei Beliankou Date: 2010-08-09T00:59:22+09:00 Subject: Re: Hel;p with Tip Calculator On Mon, 9 Aug 2010 00:46:29 +0900 Hd Pwnz0r wrote: > puts "What is the total?" > input = gets.chomp.to_i > puts "What percent do you want to tip?" > input2 = gets.chomp.to_i > percent = 100 > tip = input2 * input * 0.01 > puts "You should tip $#{tip}" > > This is a tip calculator. I want it to work if the person enters $45 > or 15%. > > Right now, it would only return 0 because they are invalid numbers. It > would only work with an input of 15 or 45. I have really no clue how > to do that. Use '45 %'.sub(/%/, '').strip '14 $'.sub(/[$]/, '').strip for that. "strip" can remove unwanted trailing and leading blanks. "sub" substitutes the charachters in the RE with an empty string removing them. Regards, Andrei