From: Jon Lim Date: 2011-10-22T16:29:08+09:00 Subject: Re: power of 2 code --0015174483aa0e337204afde25dc Content-Type: text/plain; charset=UTF-8 His example is wrong, as the result should be 2^16 ruby-1.9.2-p180 :008 > 2**17 => 131072 ruby-1.9.2-p180 :009 > 2**16 => 65536 If you are learning, recommend: https://pine.fm/LearnToProgram/ On Sat, Oct 22, 2011 at 05:37, Ray DarkScythe wrote: > hello I am new here and new to ruby (no programming experience but > willing to learn) > > I am following "Daniel Carrera" tutorial I am already at while loops and > fairly I understand of it but the one thats bugging me is the exercise > of the power of 2. > > heres the exercise: > > Rewrite this last program so that the computer asks for the maximum > number and the program computes the corresponding power of two. > > Enter maximum value: > 124123 > 2^17 =131072 is the highest power of 2 less than 124123 > > > heres my code; > > puts "Enter a maximum value: " > number =gets.chomp.to_i > high =number > while number < 10_000 > number *= 2 > end > puts high.to_s + " is the highest " + \ > "power of 2 less than " + number.to_s > > > this is the site: > http://localdoc.scusa.lsu.edu/ruby/Tutorial/part_02/while.html > > thanks for anyone answering > > -- > Posted via http://www.ruby-forum.com/. > > --0015174483aa0e337204afde25dc--