Subscript must have integral type

Hi, for the piece of code I'm working on at the moment I've encountered a fairly basic problem that is giving me some issues. Here is the code in question:

1
2
3
4
5
6
7
		double random;
		random = pRanGen->Random();
		double atom = random;

		// Save the old coordinates
                double old_coords[3] =  { coords[atom][0], coords[atom][1],
                                         coords[atom][2] };


The problem here is my variable type. If I declare atom as an int then my random number generator 'RanGen'(which only accepts doubles) spouts out only 0's due to converting from a double to an int. If I declare atom as a double then the number generator works and I get a range of values for atom, but my coordinate system no longer works. The way I have that 'old_coords' set up it only accepts atom as an int. If atom is a double it tells me that the subscript must have an integral type.

Any help much appreciated.
you can use casting like
int atom = static_cast<int> random;
hope this will help you but,
i don't know whether this will work for your program or not...
closed account (DSLq5Di1)
After a bit of googling, I think I've found the library you are using.. http://www.agner.org/random/ ?

CRandomMersenne has the following functions that return an integer,
1
2
int IRandom (int min, int max);
int IRandomX (int min, int max); // more accurate but slower, read the documentation for details 

You'll need to generate a value within the bounds of your array if you wish to use it as an index.
Topic archived. No new replies allowed.