I'm trying to write code that prints a number input by a user in a right triangle. For example, if 8
is entered, it should look as below:
*
**
* *
* *
* *
* *
* *
********
1
12
123
1234
12345
123456
1234567
123345678
I'm trying to get this to work:
puts " Enter a number: "
number = gets.to_i
puts "*" * number
count = 0
while count < number - 2
print "*"
print " " * (number - 2)
puts "*"
count += 1
end
puts "*" * number
The result comes out as a square. This is what I get:
*****
* *
* *
* *
*****
Where am I going wrong?