Ruby

Moderators: None (Apply to moderate this forum)
Number of threads: 37
Number of posts: 70

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
I'm having trouble making ruby guessing game. Posted by JonathanO on 6 Oct 2009 at 8:12 AM
I can't seem to make my program loop to make it continuously ask the user to guess the number.
Report
Re: I'm having trouble making ruby guessing game. Posted by rbdul on 3 Dec 2009 at 12:41 PM
I hope that someone can help you soon.
Report
This post has been deleted. Posted by rbdul on 3 Dec 2009 at 12:43 PM
This post has been deleted.
Report
Re: I'm having trouble making ruby guessing game. Posted by gmbrown on 6 Nov 2011 at 3:39 PM
Here is an example:

max = 10
if ARGV.size > 0
max = ARGV[0].to_i
end

puts "I'm choosing a number between 1 and #{max}"
num = rand(max) + 1
loop do
print "Enter guess: "
reply = STDIN.gets.chomp.to_i
if reply == num
puts "You guessed it"
break
elsif num < reply
puts "Lower"
else
puts "Higher"
end
end




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.