Hello Guys

Well I'm working on a lottery game and I would like to ask something because I don't know how to test the sequence of numbers before to print out!!
All I need is to check the series of numbers in the arrays before the program prints out a random number if the number is the same then the program will make another randomization series,

Examples

int BOARD_2012_M7_K09[5] = {1,4,6,10,41};

If the random numbers are 1,4,6,10,41 (in different sequence also 41,10,4,6,1) Then the program will make a new random sequence !!
With other words I missing the checking part which probably will be with an if statement and I don't know where to put it to be logically !!

Any help welcome !!

Below it's my code !!!

    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    #include <sstream>


    using namespace std;

    int main (int argc, char * const argv[]) {

        int numberCount;
        int maxNumbers;
        int counter = 0;


             int BOARD_2012_M7_K01[5] = {5,6,18,19,34};
             int BOARD_2012_M7_K02[5] = {5,25,28,29,40};
             int BOARD_2012_M7_K03[5] = {17,24,26,37,43};
             int BOARD_2012_M7_K04[5] = {1,8,14,34,42};
             int BOARD_2012_M7_K05[5] = {19,26,31,32,42};
             int BOARD_2012_M7_K06[5] = {5,14,27,35,40};
             int BOARD_2012_M7_K07[5] = {28,32,33,37,43};
             int BOARD_2012_M7_K08[5] = {2,13,18,41,45};
             int BOARD_2012_M7_K09[5] = {1,4,6,10,41};



        cout << "Lottery Game" << endl << "=================================" << endl;
        cout << "How many Lottery Numbers = ";
        cin >> numberCount;
        cout << "from 1 to ? ";
        cin >> maxNumbers;
        cout << "You have chosen " << numberCount << " Lottery Numbers from 1 to " << maxNumbers << endl;

        int lotteryNumbers[numberCount];
        int i, j;
        bool newNumber;
        long t;

        srand(time(NULL));
        for (t=0; t<10; t++){


        for(i=0; i<numberCount; i++) // get numbers
        {
            do
            {   // Check Random
                lotteryNumbers[i] = rand() % maxNumbers + 1;

                newNumber = true;
                for (j=0; j<i; j++)
                {
                    if (lotteryNumbers[i]==lotteryNumbers[j])
                    { // Check for existing numbers
                        newNumber = false;
                    }
                    else
                         switch (lotteryNumbers[j])
                         {
                       lotteryNumbers[i] = rand() % maxNumbers + 1;
                                             newNumber = true;
                                 }


                }
            } while (!newNumber);
        }
        for (i=0; i<numberCount; i++)
        {
            cout << lotteryNumbers[i] << " ";
        }
        cout <<"("<<counter++<<")"<< endl;




}
}

You could make a copy of the series of numbers,
then sort the copies,
and then compare the sorted series to see if the same.

can you be more specific by showing me an example ? Thank you !!

Take a look at this little demo ...

#include <iostream>

// re comparing two arrays to see if hold 'equal' items ... //
#include <vector>
#include <algorithm> // re. vector sort ... //


using namespace std;


// print out a vector to ostream ...
ostream& operator << ( ostream& os, const vector< int >& v )
{
    vector< int >::const_iterator it;
    for( it = v.begin(); it != v.end(); ++it )
         os << ' ' << *it;
    return os;
}

// passed in arrays must be at least size 'size' ... //
bool equals( const int a[], const int b[], int size )
{
    vector< int > va( a, a+size ); // construct vector copy
    vector< int > vb( b, b+size ); // construct vector copy

    sort( va.begin(), va.end() );
    sort( vb.begin(), vb.end() );

    cout << "'a' sorted = " << va << endl;
    cout << "'b' sorted = " << vb << endl;

    return va == vb;
}

void pause()
{
    cout << "\nPress 'Enter' to continue ... " << flush;
    cin.get();
    cin.sync();
}


int main()
{
    int board[][5] =
    {
        {5,6,18,19,34},
        {5,25,28,29,40},
        {17,24,26,37,43},
        {1,8,14,34,42},
        {19,26,31,32,42},
        {5,14,27,35,40},
        {28,32,33,37,43},
        {2,13,18,41,45},
        {1,4,6,10,41}
    };
    int size = sizeof board / sizeof *board;
    cout << "size = " << size << endl; // 9 //



    // see if beginning row has same items as any other row

    bool redundant = false;
    for( int i = 1; i < size; ++i ) // start with i = 1 ... //
    {
        if( equals( board[0], board[i], 5 ) )
        {
            cout << "row '0' 'equals' row '" << i << "'\n";
            redundant = true;
        }
    }
    if( redundant ) cout << "There was a redundant row ...\n";


    pause();

    redundant = false;
    for( int i = 0; i < size; ++i )
         for( int j = 0; j < size; ++j )
        {
            if( i != j && equals( board[j], board[i], 5 ) )
            {
                cout << "row '" << j
                     << "' 'equals' row '" << i << "'\n";
                redundant = true;
                // break; // can break here if wish
            }
        }
    if( redundant ) cout << "There was a redundant row ...\n";

    pause();
}

Thank you david this code was very helpful

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.