Your function main()
is declared as type (int)
. This means that whenever this function is used, we can expect that once it finishes executing, we'll receive some integer from it.
The way main()
will give us that integer is by using a line that starts return...
. So essentially, when we call main()
, as you do by typing in ./mario
, or whatever at the terminal, it sets about looking for an int
.
When it gets to your line of code that says return(stepHeight);
, it thinks that stepHeight
is the variable we were looking for, and it exits before running your for-loop
.
To fix this, remove the return
line from where it is, and add a new line at the very end of main, just before the last }
. For this line you want something like this: return 0;
.
Why 0? It's arbitrary...we could return anything, because for this program we don't really care so much about what is returned as we do what is printed. But in general, for functions where we care more about what they do than what they return, we use the return value to tell us about how the function did. 0 is commonly used to say, the function operated as expected.
As you get into more complicated programs, it'll be common to put return statements in different places in your function, sometimes causing a function to exit early, if for example, the inputs are unexpected, but for now, it's probably best to just keep the return statement at the very bottom of your main() function.
If you do this and you still don't see your message printing, be sure to take a close look at the condition in your for
loop, particularly the condition for continuation:
for (int i = 0; i == stepHeight; i++)
The for
loop only executes if the second term is TRUE
. If stepHeight
is 16
or something, i == stepHeight
will be FALSE
. Try to think of a condition to put there that will be TRUE
at first and then later, as i
gets bigger will change to FALSE
.
https://www.diffchecker.com/ct7wavau
HTH
If this answers your question please accept it by clicking the gray check-mark to the left, so that it becomes green. You can also vote it up by pressing the up arrow above the check-mark