0

So I have been working on CS50's pset 1, making marios half pyramid. I have been looking over other problems on this site and I've gotten this far. But I can't seem to see what the problem is with my hashes. It seems like one of my lines isn't even being accessed because if I move it up in the command absolutely nothing changes in the program. I've even found a working program with the same info using while loops instead of for loops. Is that my only problem? Does anyone see anything that would cause a problem with the hashes? i hope this shows my code

0


We can't give you the whole answer but we will guide you until you find it!
In the second for loop ( the one that prints hash ), there is a problem in the initialization. Let's test it !
In the first time we will initialize hash with height, test if hash <= height (Yes), then we execute the printf. Now we will increment the hash variable, test if hash <= height (No), the for loop stops. As you can see the for loop will print only one hash every time you execute it, that's why there is only one hash when you execute :)
Hope this was helpful

0

Ahmed is correct with that part. The second loop will always execute exactly once.

You have another issue to deal with though. You initialize and allocate hash in two different places, first on line 17 and then on line 33. This is usually not a good practice.

You are also manipulating the value of hash by decrementing on 33 and altering with lines 40 thru 42. In other words, it looks like you're following two different sets of logic when you are using the var hash. I'll leave it to you to figure out how you wish to clean it up.

You must log in to answer this question.

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