+ 2
Hourglass and For Loops
Hello!! I wrote this code: https://code.sololearn.com/cbne3YJXCuF7/?ref=app I was wondering how to get rid of the extra row of 3 *’s in the middle... also, I have to print “Invalid number of rows.” if rows is less than 1 or if rows is a number that leads to a row in the hour glass with less than two *’s. *WANT*: (If 7 and 3 are entered) ******* ***** *** ***** ******* ... the spaces kind of mess up here, but it should be right.
4 Respostas
+ 6
Your outer loops is based on topRows - equivalent to the width, not the height - which can lead to missing lines as the input becomes larger. It's a bit hard to follow with all the variable naming, so I'm sorry to say that I'm unable to point out which part is correct and which part isn't.
Here's my version. It can take any input, as long as they're integers. I also named the variables differently for more readability.
https://code.sololearn.com/cA0y3CTzC9kB/#cpp
+ 5
Although Hoàng Nguyễn Văn has answered your question in an amazing manner I think this might help...
https://code.sololearn.com/cJ2P34jkeCHR/?ref=app
+ 1
Miqaela Weller as per in my code if you will convert k = i to k = i - 1 that should do the work
0
How do I get rid of the intital space in the beginning? its like the whole hourglass needs to move to the left one.