program crash.

My code compiles fine, but when it comes to running it, it crashes. As soon as i input line 11 it makes the .exe program crash when it stats up. I have no idea what it is so i was wondering if someone on here could lend me a hand.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 int enemyStats(vector<int>&ENEMY_STATS,vector<int>PLAYER_STATS,vector<string>stats){
    ENEMY_STATS[1]=PLAYER_STATS[1];
    vector<int>::iterator iter;
    srand(time(0));
    int Stats=rand()%100+1;
    ENEMY_STATS[0]=Stats;
    int points=ENEMY_STATS[1]*40;
    for(iter=ENEMY_STATS.begin();iter!=ENEMY_STATS.end();++iter){
        Stats=rand()%points+1;
        *iter=Stats;
        points-=Stats; //just here
    }
        vector<int>::iterator inIter;
    vector<string>::const_iterator stIter;
    stIter=stats.begin();
        for(inIter=ENEMY_STATS.begin();inIter!=ENEMY_STATS.end();++inIter){
            cout<<*stIter++<<"\t";
            cout<<*inIter<<endl;
            }
}

Thanks for all the help people on here have been giving me recently.
Just in case it helps im using windows seven 64-bit, code blocks 13.12 any other info that is needed just comment.
Last edited on
 
*iter=Stats;


what is this?
makes what ever *iter is referring to equal stats.
Example if stats equal 20 and *iter is referring to position 4 then position 4 will equal 20.

Here is what all the stat stuff equal.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    vector<string>stats;
    stats.push_back("xp\t");
    stats.push_back("level\t");
    stats.push_back("attack\t");
    stats.push_back("defence\t");
    stats.push_back("health\t");
    stats.push_back("speed\t");
    stats.push_back("accuracy");
    stats.push_back("luck\t");
//declaring the players stats
    vector<int>PLAYER_STATS;
    PLAYER_STATS.push_back (100);//xp
    PLAYER_STATS.push_back (1);//players level
    PLAYER_STATS.push_back (5);//Attack
    PLAYER_STATS.push_back (10);//defence
    PLAYER_STATS.push_back (15);//health
    PLAYER_STATS.push_back (7);//speed
    PLAYER_STATS.push_back (7);//accuracy
    PLAYER_STATS.push_back (10);//luck
//declaring enemy stats
    vector<int>ENEMY_STATS;
    ENEMY_STATS.push_back (0);//xp
    ENEMY_STATS.push_back (0);//Enemy level
    ENEMY_STATS.push_back (0);//Attack
    ENEMY_STATS.push_back (0);//defence
    ENEMY_STATS.push_back (0);//health
    ENEMY_STATS.push_back (0);//speed
    ENEMY_STATS.push_back (0);//accuracy 
Are you sure the problem isn't actually on line 9 where it would appear that division by 0 is not only possible, but very likely?
It could be. Will try sort that out see if it helps. Thanks
Last edited on
Thanks i just put a
if (points==0)
break;

and now it seems to be working.
Topic archived. No new replies allowed.