I have done my mario.c all correct but the cs50 check says: ':( rejects a height of 9, and then accepts a height of 2 expected exit code 0, not 2' Why I have this problem? Idon't understend. When I testing, everithing work perfectly. Please, help me!
I've seen this several times and I wonder why. Well the return statement, inside the main function, causes the immediate termination of the program, with an integer that returns main, remember the declaration of main:
main should return an integer, it could be any, but by convention, main will return zero at the end, when the program ends and we know that it has been executed correctly. Therefore we must return zero if we reach the end:
and do not return h as you do in your program. The zero, as a standard value, is used by check 50 to check the correct end of the program. The convention says that if we return a non-zero value in main, it's that something went wrong and we're not going to get to the end of the program for any reason. One of these reasons may be, for example, that the user does not collaborate and gives us incorrect values for the pyramid. We can choose to ask again or just leave with a code of 1 or 2 or 3 ... as a sign that something did not go well.