A Very Good Morning to you,  
Hi and how do you do ?  
I hope your day is going great.  
I would like help writing a CPP Function() with the following criteria :-  
It is to search for 4 digit numbers in a Pick 4 Game.  
1. Given a 2D Array of 4 Digit Number from 0 to 9  
   Lets call this 2D array - Array 1  
   This Array consists of only 9 sets of 4 digit random numbers  
   Digits can be repeated up to 4 times  
   e.g. - 0000 or 0001 or 0012 or 0123 or 1234 or 2342 or 3422 or 5676 or 5644  
2. Given a 2D Array of 4 Digit Numbers from 0 to 9  
   Lets call this 2d array - Array 2  
   This Array consists of say 1000 sets of 4 digit random numbers  
   Digits can be repeated up to 4 times  
    e.g. -  0000  
            0001  
            0012  
            0123  
            1234  
            3242  
            3453  
            6575  
            6786  
            8797  
            2342  
            3453          
Questions -  
-----------                                                   
Point A. 
   How can I search for all the 9 numbers from Array 1 in Array 2 with the following number criteria -  
   A. If all 4 digits in Array 1 are unique, find all combination of this 4 digits in Array 2  
   B. 1 digit from Array 1 can be an Exception - Meaning it can be a differnt number out of the 3 in Array 1     
   e.g. -   
   First Number in Array 1 to Search from Array 2 = 1234     
   Result of search in Array 2 will return - 1234 2134 4321 3214 2143 etc etc     
   Result of search from Array 2 will also include 4 digit numbers where 1 digit from Array 1 that can be     
   Different     
   look at this example - where 3 digits are found in Array 1 and 1 digit can be different out of the 4 
   digits found in Array 1   
   - e.g. 1238  2135  4372 3941 9421 4326 2149 2364 4351 1428 etc etc          
Point B. 
   Now Array 1 can have duplicate random digits e.g. - 0000 1111 2222 3333 4444 0001 0012 0123 1234 
   For duplicate digits numbers in Array 1 - The Search for digits in Array 2 has the same criteria as Point A.    
   .e.g - Array 1 = 0012
   - Search Returns - 2100 0012 0210 0120 1200 2100 2001 etc etc
   - Search also returns Numbers where 1 number from Array 1 can be different in Array 2                                                         
   e.g. - 2101 2102 2103 9012 8120 7210 8001 6002 2170 0127 0001 2210 1100 1208 0002 1100 1204 4002 2103 etc etc -         
Can some kind soul please kindly write this CPP Function for me ???
Thank you very much for your time.
I hope you have a Great Day Ahead.    

I am sorry - I am trying to Post some TEXT and the only way I can do so is to use the Code Formatting.

Sorry ... 

Recommended Answers

All 5 Replies

I think you've come to the wrong place. This is a place to help people with specific problems, mostly in code that they've already written. You need a site where you can hire a professional to do this. This is one such site. Unless of course you do have some code that you need help with, then by all means show us the code and describe the problem and we'll be more than happy to help you.

commented: Excellent response! :) +13
Sorry - Here is what I have coded so far -

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <memory.h>
#include <dos.h>

void main(void)
{
    FILE *fileptr;

    int **mainnum_db;
    int dbRows, dbCols;
    int db_index;

    int **FourD_db;
    int sgtotoRows, sgtotoCols;

    int char1, char2, char3, charx;

    int x, y, z;
    int a, b, c, d, e, f, g;

    int dbVal1 ,dbVal2, dbVal3, dbVal4, dbVal5, dbVal6, dbVal7, dbVal8;

    int dbValx[10];

    int theNUMBZ[50];

    dbRows=1000;
    dbCols=7;

    if((mainnum_db = (int **)malloc(dbRows * sizeof(int*)))==NULL)
    {
        printf("Memory Allocation Failed\n");
        exit(0);
    }
    for(x=0;x!=dbRows;x++)
    {
        if((mainnum_db[x] = (int *)malloc(dbCols * sizeof(int)))==NULL)
        {
            printf("Memory Allocation Failed\n");
            exit(0);
        }
    }

    for(x=0;x!=1000;x++)
        for(y=0;y!=dbCols;y++)
            mainnum_db[x][y]=0;

    fileptr=fopen("4d RAW database - Format C.txt", "r"); 

    y=0;
    x=0;

    while(!feof(fileptr))
    {
        fscanf(fileptr,"%1d%1d%1d%1d,",&dbVal1,&dbVal2,&dbVal3,&dbVal4);

        mainnum_db[x][0]=dbVal1;
        mainnum_db[x][1]=dbVal2;
        mainnum_db[x][2]=dbVal3;    
        mainnum_db[x][3]=dbVal4;    

        x++;
    }
    x--;
    db_index=x;

    fclose(fileptr);

    sgtotoRows=18;      
    sgtotoCols=7;

    if((FourD_db = (int **)malloc(sgtotoRows * sizeof(int*)))==NULL)
    {
        printf("Memory Allocation Failed\n");
        exit(0);
    }
    for(x=0;x!=sgtotoRows;x++)
    {
        if((FourD_db[x] = (int *)malloc(sgtotoCols * sizeof(int)))==NULL)
        {
            printf("Memory Allocation Failed\n");
            exit(0);
        }
    }

    for(x=0;x!=sgtotoRows;x++)
        for(y=0;y!=sgtotoCols;y++)
            FourD_db[x][y]=0;

    fileptr=fopen("4d master preditions.txt", "r"); 

    for(x=0;x!=9;x++)
    {
        fscanf(fileptr,"%1d%1d%1d%1d,",&dbVal1,&dbVal2,&dbVal3,&dbVal4);
        FourD_db[x][0]=dbVal1;
        FourD_db[x][1]=dbVal2;
        FourD_db[x][2]=dbVal3;  
        FourD_db[x][3]=dbVal4;  
    }

    fclose(fileptr);
a=0;
b=0;
c=0;
d=0;
e=0;
f=0;

for(x=0;x!=9;x++)
{   
    dbValx[0]=FourD_db[x][0];
    dbValx[1]=FourD_db[x][1];
    dbValx[2]=FourD_db[x][2];
    dbValx[3]=FourD_db[x][3];

    printf("[%1d][%d%d%d%d] : ",x+1,FourD_db[x][0],FourD_db[x][1],FourD_db[x][2],FourD_db[x][3]);

    for(y=0;y!=db_index;y++)
    {
        b=0;
        c=0;
        for(z=0;z!=5;z++)
        {
            if(dbValx[c]==mainnum_db[y][z])
                b++;
            c++;
        }
        if(b >= 3)
        {
            printf("[%d%d%d%d]",mainnum_db[y][0],mainnum_db[y][1],mainnum_db[y][2],mainnum_db[y][3]);
        }
    }
    printf("\n\n");
}
    for(x=0; x<sgtotoCols; x++)
        free(FourD_db[x]);
    free(FourD_db);

    for(x=0; x<dbCols; x++)
        free(mainnum_db[x]);
    free(mainnum_db);

}
Contents of file - 4d master preditions.txt

0000,0001,0012,0123,1234,5845,5940,2589,9882,

A small sample of the contents of file - 4d RAW database - Format C.txt

5729,2795,5679,6795,7596,7569,7350,5730,5703,5370,0607,6007,0760,7006,7043,3047,7340,4073,0932,2039,3209,2093,2709,0972,2097,7029,6647,7664,0758,8705,0875,9365,3965,5396,1908,1089,1809,3948,8349,4839,0945,4095,5049,6925,9652,5296,2496,6924,2964,1929,9921,2919,1035,1053,3510,8716,1678,6836,6683,8663,6705,7506,6750,5389,3598,9385,0907,7090,0709,7937,9773,7739,6024,2406,3484,4348,2849,4829,1293,3129,1251,5112,2398,8239,1690,6109,1380,6384,6843,3548,4835,3304,3034,7513,1735,5681,8651,3587,3875,2962,6229,0903,6027,7260,7174,7741,6299,2699,5088,0885,7756,7567,7635,3675,7486,4786,7390,9307,6872,7826,5064,6054,4995,4599,6023,3026,0236,2306,2603,0623,0632,6230,0362,3260,3620,6032,1258,1285,1825,8521,5182,2158,8215,5218,5281,2518,5821,2581,8452,2485,2458,4528,5248,5824,4852,4825,8542,2584,4258,2548,0726,2067,2076,2607,2670,7620,7602,6207,0267,6027,0276,6072,0627,2045,5042,0452,4520,4250,0245,4052,2450,5420,0542,2540,2504,5204,3054,4035,0534,0543,5340,0354,5043,3540,0435,4530,3405,4350,3716,7631,

And what problem do you have with the code?

Also, this doesn't appear to be C++...

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.