I've finally gotten some loops nesting properly and building a type of pyramid. I'm not sure where I've gone wrong that the hashes are repeating a few times on the same line and the spaces (rendered as dots for now to make it clearer for myself) aren't behaving properly. Can anyone guide me to where I might fix my mistake? I'm happy I'm actually printing a semi-pyramid at least!!
1 Answer
the pseudocode for Mario
for height of pyramid
for (calculate nr. of spaces at height)
print ' '
for (calculate nr. of hashes at height)
print '#'
print a newline
I'd defer from saying more since, well, that would kill all the fun of the problem :)
Note that you've got other problems, too... your conditions aren't correct. You should use pen and paper to write out your conditions and manually write a table for each line, what the values of hash and sp are.
-
to me, it seems like that's what I have. Are you suggesting I "unnest" my loops? Jul 8, 2015 at 11:44
-
That's exactly what I'm suggesting. Perhaps writing your code more in line with the manual.cs50.net/style coding standard would make it easier for you to debug.– AndrejJul 8, 2015 at 11:47
-
I edited my code so it looks nicer, but when I take out the curly brackets it stops printing a pyramid and just prints a straight line. I have been working on this for weeks and hadn't gotten a pyramid yet so I feel like I'm on the right track, any further help would be appreciated Jul 8, 2015 at 12:03
-
-
yes, when I un-nest it prints in straight lines and doesn't resemble a pyramid at all, and from reading all the questions regarding the pyramid on this forum I've gathered its supposed to be a nested loop? Can you explain why it's NOT supposed to be nested? Jul 8, 2015 at 12:11