Unhandled Exception - Divide-error Exception RPGDM.CPP 2394

Hello, I'm getting the above error when I try to run the following code, and it gets to the marked line. The game stops and I get a blue bar going across that line, and I can't seem to figure out whats wrong with it.
1
2
3
4
5
6
7
8
9
10
11
12
 if (mapinfo[clvl][53]==0)
 {
  ltemp=rand()%1000+1;
  ltemp2=allskills[3]*3;
  ltemp+=rand()%ltemp2+0; // ** CRASHES
  if (ltemp>750)
  {
	for (cplayer=0;cplayer!=4;cplayer++)
	 cstats[cplayer][rand()%6]++;
  }
  else printf ("\n");
 }


I'm also getting it on these two lines:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 if (selectedmove==0)
 {
  // DEX Roll vs. Enmy DEX for hit
  theyroll=rand()%cmonstats[selectedenemy][_DEX]-1;  // ** CRASHES
  myroll=rand()%cstats[cplayer][_DEX];               // ** CRASHES
  if (myroll>theyroll)
	printf ("Attack sucessful\n");
  else if (theyroll>=myroll)
	printf ("Attack dodged\n");
  // STR Roll vs. Enmy STA for damage
  myroll=rand()%cstats[cplayer][_STR];
  theyroll=rand()%cmonstats[selectedenemy][_STA];
  weroll=myroll-theyroll;
  // Deal damage
  if (weroll>0)
  {
	cmonstats[selectedenemy][_HP]-=weroll;
	printf ("You hit for %d\n",weroll);
  }
  else printf ("Did 0 or less damage\n");
  dir=getche(); // ** TEMP
  return;
 }


Any help would be greatly appreciated, thank you!
Since we are lacking a huge amount of information to debug this, I'll just pass you a reference pointer to something you might want to read.

http://cplusplus.com/doc/tutorial/exceptions/

EDIT: Divide-error, you idiotic albatross. You need more coffee.

-Albatross
Last edited on
Check that every right hand operand for % is not zero.
Albatross: Thank you for the help, but the information you linked me to went WAY over my head. I tend to get buried in unknown lingo when I try to look it up myself.

helios: That's it! The variables listed were all equal to 0 the times that it crashed, it was only a simple statement of if (variable!=0) away from working perfectly, thank you!
Last edited on
Topic archived. No new replies allowed.