Hello all. I started making my own function for combat to use in a program I'm working on. The problem is, I'm not sure what type the function should be: void or int? And if it is int, what do I return? Also, I'm getting a strange error that reads as: "label must be followed by statement." Uh...what?
The complaint is on line 48. loop is a label. It must have a statement after it, not a brace.
As for return code, it entirely depends on what you want the function to do.
It looks like the function returns when either the player or the enemy dies, so perhaps you want
the function to return true if the player is still alive and false if the player dies.
OH! *face palm*
That makes so much sense. I don't think I entirely understand what return is supposed to do, but that certainly helps. Mucho Kudos jsmith.
// This function returns x^2.
int square( int x ) {
int result = x * x;
return result; // Tells the compiler that the value you want to result is stored in result
}
Without the "return" statement, the compiler would not know what value to return from the function to the caller.