# Thread: Beginner needs help w/ran. nums. in arrays - URGENT!

1. ## Beginner needs help w/ran. nums. in arrays - URGENT!

I need to create a program that generates 50 sets of lotto picks each set consisting of 6 numbers between 1 - 54. each set must contain 6 unique numbers. The set themselves do not need to be unique from each other. That is the question - the problem is that when I run the program all I get is what looks like a memory adddress ( 006AF948).
Any help would be greatly appreciated as my instructor didn't get back to me with this assignment till Monday and it is due Wed. The program is as follows. If I am understanding 2D arrays (probably not ;( ) would what I have not put a random number in each element? Thanks for any and all help.

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
//declare array
int lottoNums[50][6] = {0};

//declare variables
int row = 0;
int col = 0;
int number = 0;

//initialize the random number generator
srand(time(NULL));

//generate random numbers
number = 1 + rand() % (54 - 1 + 1);

while (row < 50)
{
col = 0;
while (col < 6)
{
lottoNums[row][col] = number;
col = col + 1;
}//end while
row = row + 1;
}//end while

//display lottery numbers
cout << "Here are your 50 sets of lotto picks:" << endl;
cout << lottoNums;

return 0;
}//end of main function

2. It's not so strange since you are writing out the address of the lottoNums array.

3. Ok, as I said I am a beginner - how did I manage to do that? How do I get the random number into each element properly?

4. You have 2 basic problems, firstly, the problem that gliptic is talking about. You are not writing out the contents of the array. You will need to write out each element. Heres a clue...

cout << lottoNums[0][0];

... but use loops.

When you have fixed that, (and possibly added some formatting), you will find that all the elements have the same value, that is because you are calling the random number function once only. You need to call it for each new random number.

Popular pages Recent additions