im new to ruby...... and i need some help!
im trying to make a quick app that takes an array of #'s
puts them into a specific order ( i thik ill use the method "list" for
that?"
and gets the mean, median and mode of the array of numbers?
how would i get what the user enters and puts it in
this is what i got so far
array = {}
num = gets.to_i
while num != 000
*please note the "while num != 000" is for when the user enters 000, the
program knows when to stop adding numbers to the array, and to get the
mean median and mode
Is this a homework assignment? while num != 000 is not going to do what you
expect. It will catch 0, 00, 000, 0000, 00000... as to_i converts those to
0.
also you would want to write it as
while num != 000
num = gets.to_i
array << num
end
···
On Fri, Aug 15, 2008 at 3:03 PM, Daniel Kindler <gizabo@yahoo.com> wrote:
im new to ruby...... and i need some help!
im trying to make a quick app that takes an array of #'s
puts them into a specific order ( i thik ill use the method "list" for
that?"
and gets the mean, median and mode of the array of numbers?
how would i get what the user enters and puts it in
this is what i got so far
array = {}
num = gets.to_i
while num != 000
*please note the "while num != 000" is for when the user enters 000, the
program knows when to stop adding numbers to the array, and to get the
mean median and mode
And of course, many excellent books, and readily written software packages (in your case,
search e.g., for the statistics2 package on the RAA (Ruby Application Archive).
If you want the array data as a string (i.e. one line) you can use the join
method:
puts array.join(' ') would print the numbers in the array separated by
spaces
puts array.join(',') would separate the elements with a comma
You can separate them with whatever you want, it can even be multiple
characters.
···
On Fri, Aug 15, 2008 at 4:21 PM, Daniel Kindler <gizabo@yahoo.com> wrote:
Daniel Kindler wrote:
> ok this is what i wrote so far
>
>
>
> array =
> num = gets.to_i
> while num != 000
> num = gets.to_i
> array << num
> array.sort
> end
>
>
>
>
>
> why wont if list out the numbers?
nvm i relized i didnt add the "puts"
but it comes out like this
Le Fri, 15 Aug 2008 18:06:38 -0500, Daniel Kindler <gizabo@yahoo.com> a écrit :
array =
num = gets.to_i
while num != 0
num = gets.to_i
array << num
end
puts array.sort.join(',')
works well so far
Now, how would i take the numbers in the array, and add them......