Question: can someone please help me with this simple program in Ruby, (NOT Rails) Write a program that accepts 5 numbers (floats) and displays their average

can someone please help me with this simple program in Ruby, (NOT Rails)

Write a program that accepts 5 numbers (floats) and displays their average (floats).

Example Input: 1 2 3 4 5

Example Output:

Enter 5 numbers:

Average: 3.0

Tip: ------------------------- You can loop through an array of numbers like this.

Then you can do something with x which is an element of the array

numbers.each do |x| ...

end

or (in one line of code)

numbers.each { |x| ... }

for example if I wanted to print each item I would do:

numbers.each do |x| puts x end

or (in one line of code)

numbers.each { |x| puts x }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!