C++ Battle Game Crashing

Ive tried to fix certain things on this for a while and recently its just been crashing so much I dont know where Ive gone wrong, Im an absolute noob at C++ and so I can see where the crashes are happening wheather something is being divided by 0 or variables are not being reset I dont know but I really need the help of people who are at least a little bit good at c++

http://pastebin.com/nv3jiT60

the game often crashes when you select a character which it usually doesent, and when you refresh your character and when you replay the game :C
Please if you spot anything wrong with it point it out with some advice on what to do or whatever you think is best, I know there is no better way to learn that through errors so I do want to know what is wrong and how to fix it if i ever encounter it again

Much appreciated and thank you for your time
I didn't read everything but here's something which is likely causing a ton of problems in your program:

1
2
3
    while(Running = 1){
        system("cls");
        srand(time(0));


You need srand(time(0)); to be at the very start of int main. If it's in the loop, you're going to get the same 'random' number every time, instead of it generating new ones like it's supposed to.

Also, you should look into learning what Classes are so you don't have a massive bunch of messy variables for all of your stats at the start like you have in the global area.


EDIT: After looking through the code a little more, I see that you're not really making good use of the While loop. You're setting a value in the parameters (while(OpponentChoiceRunning = 1)) when you should be checking for a condition there. For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
bool Running = true;

while(Running) // or you could have while(Running == true), note the double ==.
{
    //some code...
    if(somethingToEndTheLoop){
        // two ways to exit:
        break; // break from the current loop.
        Running = false; // set to false, while(Running) is now false and won't loop.
    }
}

// or

int Timer = 5;

while(Timer > 0)
{
    //some code...
    Timer--; // this will quit after 5 loops, but for this you'd be better off using a For loop
}
Last edited on
line 186. You use operator= instead of operator==.

Make sure that the right operand of % is not 0. This can happen in a number of places in your code.
Topic archived. No new replies allowed.