0

I am very close to finishing pset1 but there's just one problem: the user needs to keep entering the height of the pyramid in order to keep printing the rest of it.

This is what I essentially have to do to build the pyramid:

     Please Indicate height: 5
                     Height: 5
    5
                            ##
    5
                           ###
    5
                          ####
    5
                         #####
    5
                        ######

See those intermittent 5's on the left of the terminal? I had to enter those in for the code to continue printing the pyramid. My question is what's going on?

I'm a bit confused as to posting my work on this website so i'm gonna err on the side of caution. here's my workflow:

//*prompt user for height

//*reprompt user if height is >23 or <0

//*store user input into variable - int i = GetInt()

//*identify variables for number of spaces (j) and number of'#'s (k)

////**print # rows using stored user input - i = GetInt()

///////***nested for loop to print number of spaces and number of #s

Any ideas? Raw code is available also.

0

Without seeing code, I'll bet that you have a loop of some kind around the prompt for the height, but you don't terminate the loop before moving on to the rest of the code, so it is reprocessing the prompt along with the code to build the pyramid. Since the pyramid code is included in the loop, it's asking for the input again.

If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)

| improve this answer | |
  • Thanks! You're right - I had to get rid of the GetInt() function in my loop which I substitute with another variable :) – dontnonuff Oct 14 '15 at 4:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .