In short gets reads a string ("11,2\n"), chomp removes the newline (enter character) ("11,2"), split creates an Array by seperating the string at every comma (["11","2"]). The map with to_i converts the two numbers to integers ([11,2]) and in Ruby you can assign an array of 2, to two variables (num1 = 11, num2 = 2).

As you can see the language is totally different

This post has been edited by Karel-Lodewijk: 16 February 2012 - 08:03 AM

In short gets reads a string ("11,2\n"), chomp removes the newline (enter character) ("11,2"), split creates an Array by seperating the string at every comma (["11","2"]). The map with to_i converts the two numbers to integers ([11,2]) and in Ruby you can assign an array of 2, to two variables (num1 = 11, num2 = 2).

Re: Two positive numbers

Posted 16 February 2012 - 08:30 AM

xclite, on 16 February 2012 - 08:00 AM, said:

So start with Ruby code.

xclite

I realize you may know everything there is to know about programming, but I don't which is why I asked a question. Please don't try to insult me or waste anyone's time with useless comments. Everyone has to learn from the beginning at some point & I'm not the only one that needs help.

Re: Two positive numbers

Posted 16 February 2012 - 08:37 AM

This is the first step to problem solving. Before you start writing code and running into road blocks, you need to have a plan. If you don't know how to decide which number should be returned, how are you going to tell a computer how to do it?

Re: Two positive numbers

Posted 16 February 2012 - 09:47 AM

xclite, on 16 February 2012 - 08:37 AM, said:

This is the first step to problem solving. Before you start writing code and running into road blocks, you need to have a plan. If you don't know how to decide which number should be returned, how are you going to tell a computer how to do it?

This is what I have now, but it's still not working:

class Screen
def cls
end
end
print "enter number1:"
num = num.gets.to_i
if num1 < 0 then print "enter a positive number"
else
if num1 < 9 and num1 > 21 then
print "enter a number in range 10-20"
end
print "enter number2:"
num2 = num2.gets.to_i
if num2 < 0 then print "enter a positive number"
else
if num2 < 9 and num2 > 21 then
print "enter a number in range 10-20"
end
if num1 > num2 then
print "the larger number is #{num1}"
else
print "the larger number is #(num2}"
end
Console_Screen.cls

This post has been edited by xclite: 16 February 2012 - 09:48 AM
Reason for edit:: Please use code tags!

Re: Two positive numbers

Posted 16 February 2012 - 09:51 AM

Let's talk about your first issue - your program is supposed to take any input > 0. Why are you asking for a new number if it's between 10 and 20? That's part of the later calculation. Also, your condition wouldn't work for that because a number cannot be < 9 and > 21 at the same time.

Re: Two positive numbers

Posted 16 February 2012 - 09:55 AM

xclite, on 16 February 2012 - 09:51 AM, said:

Let's talk about your first issue - your program is supposed to take any input > 0. Why are you asking for a new number if it's between 10 and 20? That's part of the later calculation. Also, your condition wouldn't work for that because a number cannot be < 9 and > 21 at the same time.