### Storing random values in array

I want to store my values in myArray but when I print out my array ı get some numbers like -84531868 where is the problem ?

 12345678910111213141516171819202122 int myArray[80]; void setGenerateRandNum() { srand(time(NULL)); int randX; for (int i = 0; i <= getN2(); i++) { randX = rand() % getN2() + 1; std::cout << randX << " "; myArray[i] = randX;//I want to store my values in myArray butw when ı print out my array ı get some oktadecimal numbers where is the problem ?? }
Last edited on
What do you mean by "oktadecimal"? The number you show is not octal since it has an 8 in it. Octal values only have digits from 0 to 7.

Post a complete program that demonstrates the problem.

You do realize the code you showed doesn't show you printing your array, right? How would we know what is wrong?

This is how you print out an array:
 12345 for (int i = 0; i < getN2(); i++) { std::cout << myArray[i] << " "; } std::cout << "\n";

Doing std::cout << myArray; just prints the value of the pointer (a memory address).
Last edited on
for (int i = 0; i <= getN2(); i++)

What is getN2() it should be i < 80;
Anyways...
 123456789101112131415161718192021222324 #include #include using namespace std; void fill_with_random_values(int a[]) { for (int i = 0; i < 80; i++) { a[i] = rand() % 80; } } int main() { srand(time(NULL)); int a[80]; fill_with_random_values(a); for (int i = 0; i < 80; i++) { cout << a[i] << endl; } cin.get(); return 0; }