While loop is pulling in extraneous number

I am making a space combat game for a class project, but when the combat loop starts it will sometimes put out a very small decimal along the lines of something like 3.9e-039 for the health, and I have no idea where this is coming from. This problem can be circumvented by performing a complete rebuild in codeblocks but it will only work for one playthrough.

Here is the pastebin: http://pastebin.com/41x2AVGk

The problem comes into question on lines 152 and 267 where each combat loop starts. The health goes from something normal like 475 to the small decimal mentioned earlier. Throughout the code I have placed things like health++ to try and update the health to keep it normal. I have also placed in couts to display the ships health and the current round of health for the combat loop to try and locate where my math went wrong. I suspect it has to do something with the scope of each loop.

I am trying to get another opinion on possible fixes as I have tried everything I can think of (I'm not very experienced, I'm just a beginner) and I am running short on time so I cannot completely rewrite most of the code.

Any comments and advice would be welcome.

You are assigning float value to health, so no wonder it shows as it. Just change health type to int, or cast health when viewing it in cout << health to cout << (int)health.
I took your advice and replaced health as an interger instead of a float. I also made most of the other floats into integers as well and the combat now runs fine. Thank you for your help.
Topic archived. No new replies allowed.