Question: in Ruby 11. Write a short Ruby program that uses a generate_times_table method to generate the times table for an arbitrary number x multiplied by

in Ruby 11. Write a short Ruby program that uses a generate_times_table method to generate the times table for an arbitrary number x multiplied by 1, 2, 3, up to an upper bound y. The values of x and y are supplied as input from the keyboard. In the main program, you may assume that the values entered for x and y can be converted to integers (using the to_i method) but you must ensure that y is positive. If that condition is not met, keep looping until they enter a positive number.

The code outside of the method will prompt the user for 2 values: a number to be multiplied (x) and a second number to determine how many results to generate (y).

The generate_times_table method will accept two parameters and will be passed x and y as arguments and then generate the results.

HINT: You may use x and y for both the local variables and the parameter names, or you may use m and n for the parameters if you prefer.

For this question, you will write the program and test it on students.cs.nku.edu and cut-and-paste the full text of the program into this document. Save the file on students.cs.nku.edu as times.rb so I can run tests with it if need be.

Sample output would be similar to this:

$ ./times.rb

Please input any number for x: 2

Please input a positive number for y: 10

2 * 1 = 2

2 * 2 = 4

2 * 3 = 6

2 * 4 = 8

2 * 5 = 10

2 * 6 = 12

2 * 7 = 14

2 * 8 = 16

2 * 9 = 18

2 * 10 = 20

$ ./times.rb

Please input any number for x: 2

Please input a positive number for y: -2

Please input a positive number for y: 2

2 * 1 = 2

2 * 2 = 4

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!