From: Drew Olson Date: 2007-01-06T03:41:13+09:00 Subject: Re: Problem solving quadratic equations Jay Bornhoft wrote: > I wrote a small program to solve for x using the quadratic formula but > instead of receiving a + and - result I am getting two identical > answers... > > Is the problem with my math or with my code? Seems to work for me. Remember, in ruby you can use ** for exponentiation. irb(main):001:0> a = 1 => 1 irb(main):002:0> b = 2 => 2 irb(main):003:0> c = 3 => 3 irb(main):004:0> -b + ((b**2 - 4*a*c)/(2*a))**(1/2) => -1 irb(main):005:0> -b - ((b**2 - 4*a*c)/(2*a))**(1/2) => -3 -- Posted via http://www.ruby-forum.com/.