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

This is a discussion on Beginner needs help w/ran. nums. in arrays - URGENT! within the C++ Programming forums, part of the General Programming Boards category; I need to create a program that generates 50 sets of lotto picks each set consisting of 6 numbers between ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    6

    Unhappy 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. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    164
    It's not so strange since you are writing out the address of the lottoNums array.
    // Gliptic

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    6
    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?
    Last edited by madhouse199; 12-12-2001 at 05:26 AM.

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    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.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. beginner plzz help urgent
    By sara101 in forum C Programming
    Replies: 11
    Last Post: 01-14-2007, 09:38 PM
  2. Beginner Help with returning a string of arrays
    By yuliang11 in forum C Programming
    Replies: 8
    Last Post: 12-10-2005, 02:05 PM
  3. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 08:24 PM
  4. Beginner needs help with arrays.
    By justin69enoch in forum C Programming
    Replies: 7
    Last Post: 10-25-2002, 11:44 PM
  5. arrays and functions (beginner q)
    By eazhar in forum C++ Programming
    Replies: 4
    Last Post: 07-13-2002, 05:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21