I can't get randnum to equil what is in the string at (randlong, randhigh)
AKA (x,y)
1 2 3 4 5 6 7
vector<vector<double> > countgrid;
int randhigh; // random number on the y-axis inside a grid
int randlong; // random number on the x-axis inside a grid
int randnum; // variable
randnum = countgrid[randhigh][randlong];
randnum = 0 even though countgrid[randhigh][randlong] = 3
None of the variables used to access the array are initialized. Please post something more complete.
Assumming that the values are initialized, the value returned will simply be truncated so I'd need to see a more complete example along with info on where specifically you are testing the values in the debugger.
I'm not sure exactly what you mean but I hope this helps
1 2 3 4 5 6 7 8 9 10 11 12
int height; //dimension of grid in y-axis for test =5
int length; //dimension of grid in x-axis for test =5
height++; // to avoid dividing by zero
length++; // to avoid dividing by zero
randhigh = rand() % height;
randlong = rand() % length;
height--;
length--;
// Here is a complete example that compiles and runs
#include <iostream>
int main()
{
int value(5);
std::cout << "value = " << value << std::endl;
return 0;
}
If you want help, please post an example that demonstrates the problem. I should be able to copy and paste straight into my compiler, compile, and execute the code. I shouldn't have to wonder where and/or how the variables are initialized. If you have a program that is gigantic, copy and paste the relevant parts into a separate project so that it can be compiled with a few lines of code and then post that. I'm sure folks would love to help you but you have to do your part to ensure that the question / problem is clear.