Post by Bob on Jul 23, 2011 11:38:23 GMT -8
Yeah, it's kinda funky, but I can figure most of it out. You use something I never really used/learned about in there (#pragma), which is kinda interesting. I'm trying to figure out its exact purpose. Wanna fill me in on what it does? I looked something up on Google, but I'm still kinda confused.
As for if you want to use my rstat function (above), I can give you an example of how you would use it. In your damageCalculation function, you have lines like this:
damageAmount = damageAmount * 1.5;
if you declared my rstat function somewhere above the damageCalculation function, then you would instead write it like this:
damageAmount = rstat(damageAmount * 1.5);
So what this will do is take the damageAmount, multiply it by 1.5, then pass it into the rstat function. Then, since rstat IS an int, it'll return an int for damageAmount. And since int = int, we're okay (I think damageAmount is an int anyway...if it's a double, we have fixable issues ).
A non-void function requires a different kind of return statement; that's the only difference. In a void function, you just say "return;" and it ends it, but in say, an int function, it means that when this whole function ends, it wants to end with an int. This function IS an int, so every time it finishes, it will equal an integer. So that's why we say something like "return 5" or "return temp" (if temp is an integer) or "return 0" (which is why int main() ends with a return 0).
....Make sense? Questions? Comments? Bribes?
As for if you want to use my rstat function (above), I can give you an example of how you would use it. In your damageCalculation function, you have lines like this:
damageAmount = damageAmount * 1.5;
if you declared my rstat function somewhere above the damageCalculation function, then you would instead write it like this:
damageAmount = rstat(damageAmount * 1.5);
So what this will do is take the damageAmount, multiply it by 1.5, then pass it into the rstat function. Then, since rstat IS an int, it'll return an int for damageAmount. And since int = int, we're okay (I think damageAmount is an int anyway...if it's a double, we have fixable issues ).
A non-void function requires a different kind of return statement; that's the only difference. In a void function, you just say "return;" and it ends it, but in say, an int function, it means that when this whole function ends, it wants to end with an int. This function IS an int, so every time it finishes, it will equal an integer. So that's why we say something like "return 5" or "return temp" (if temp is an integer) or "return 0" (which is why int main() ends with a return 0).
....Make sense? Questions? Comments? Bribes?