I have never seen this error before

Jul 7, 2009 at 8:17pm
The error is
"Unhandled exception at 0x00415360 in grid.exe: 0xC0000094: Integer division by zero."

what I'm trying to do is find a random number on a grid.
the grid has already been assigned with numbers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int number; // just any number
int randnum; // number assigned to the grid
int randlong; // random point along x axis
int randhigh; // random point along y axis
int height; // height of the grid
int length; // length of the grid

randhigh = rand() % height;
randlong = rand() % length;

randnum = countgrid[randhigh][randlong];
// randnum > 0

// here is the error
number = rand() % randnum;
Jul 7, 2009 at 8:33pm
It means exactly what it says: you cannot divide by zero. (Mathematically, such a thing is undefined -- so it makes no sense to try it.) Hence:
1
2
3
int a = 7;
int b = 0;
int c = a % b;
Produces a hardware interrupt which you get as "Good grief you tried to divide by zero."

Hope this helps.
Jul 7, 2009 at 8:42pm
I dont know how you grab random numbers because i'm a beginner, but maybe it is grabbing a 0. so just check to make sure it doesnt grab a 0 before performing the operation. And int the rand() % something; part of your code it looks like ur using modulus operator and maybe returning 0?

Jul 7, 2009 at 8:46pm
Ok I've found where my problem is
How do I set randnum to the number in countgrid at point randhigh, randlong?

 
randnum = countgrid[randhigh][randlong];


randnum = 0 even though countgrid[randhigh][randlong] = 3
Last edited on Jul 7, 2009 at 9:11pm
Topic archived. No new replies allowed.