Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Error with loop code jumping out of loop

$
0
0
The program that I 'm making is to make a right triangle out of asterisk (*) from the user input wi9th spaces in the middle? So an example if someone where to input a number of 4 it would look like this
*
**
* *
****. The error that I'm having is when I input 3 it should look like this

* *
** **
*** but it looks like this ****. I think it is either the count or that I need to exit out of the loop.
Thanks for any explanations or assistance in this error.


print "Enter the size of triangle: "
#size = gets.to_i
size = gets.to_i
if size > 0
  puts "*"
  if size > 1
    puts "**"
    if size > 2
      if size > 3
        count = 1
        #makes the inside of the triangle
        while (count <= (size - 3))
          puts "*" + " " * (count) +("*")
          count += 1
        end
        count - 2
      else
        #size = 3
        count = 2
      end
      print "*" * (count + 2)
    end
  end
end

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>