+ 2
Why does this line break the whole system I made?
In this code bit line 31 completely breaks the whole chance-damage system. It multiplies it completely out of proportion from a line of code that seems to have absolutely nothing to do with the calculation. I have no idea if I'm doing something wrong or what, because it works just fine if I move it somewhere else. I'm just curious as to what is causing this problem. The maximum resulting damage number should be 1000, but it goes into the 10s of millions. https://code.sololearn.com/ch8uh43kxNG4/?ref=app
3 Antworten
+ 5
As Ipang says, you only seed random once. Remove line 20.
A big part of your issue is line 15. You never initialized a value for CM, so it will start with a garbage value depending on what was left in memory at the location for that variable. Try setting it to 1 or another value that makes sense for your program/algorithm.
+ 6
Not understanding your code flow. Just wanna ask why you call srand() twice inside damage()? at line 17 and 20. Try to call srand() once in the main() instead.
+ 6
Thanks for the input, that helped a lot! I removed the extra srand() and set the default value of CM, and now it works just fine!