Hi! Here is my code of Tank Battle
when you press 1 the first tank should attack when you press 2 the second tank should attack
but when I press 1 and the first tank attacks after pressing 2 the second tank does nothing
can't find the error, help please
I came to the conclusion that lines 45 and 56 were the problem. Then I figured out that the formulas ended up with an answer that has a decimal value that you stored in an "int" variable. This will drop the decimal part which could leave a value of 0.
For a test, in the struct, I changed the "int"s to "double"s and it worked better.
If the health of the tank needs to be an "int" then try this: t1.h -= (t2.A*(1 - t1.d))*(static_cast<double>(t2.h) / static_cast<double>(t2.h0));.
Without t?.h and t?.h0 not being a double this would be integer division which drops the decimal portion and could most of the time be zero leaving the whole formula as zero. The "static_cast" will solve the problem leaving a positive number to subtract from t1 or t2.