From: Gregory Brown Date: 2009-07-28T02:33:43+09:00 Subject: Re: What is the power function On Mon, Jul 27, 2009 at 1:01 PM, Prateek Agarwal wrote: > Chris Dempsey wrote: >> I think you're looking for: >> >> 2 ** 3 => 8 > > Thanks Chris. > The following code is showing some error. Can you tell me what the > problem is? > > def power(a,b) > result=a**b > result.to_i > return result > end > > puts "a=" > a=gets > a.to_i > puts "b=" > b=gets > b.to_i > c=power(a,b) > puts "c=#{c}" String#to_i is just a function that returns an integer, it does not 'cast' a string into an integer or anything like that. This means you need to capture the return value to use it, or pass the result directly to a function. This would work: c=power(a.to_i,b.to_i) As would: a = a.to_i b = b.to_i power(a,b)