PLEASE HELP C Language Lotto Game

This is a discussion on PLEASE HELP C Language Lotto Game within the C Programming forums, part of the General Programming Boards category; -This is what I have so far. I was wondering if someone could help me finish is up. I need ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    166

    PLEASE HELP C Language Lotto Game

    -This is what I have so far. I was wondering if someone could help me finish is up. I need the user to enter 5 numbers and match theirs with the 6 random numbers that were generated in the lotto game. Then, I need to display the numbers that the user chose along with the numbers that matched that of the official lotto numbers. And then I need to prompt the user and ask if they want to play again. If they answer either 'n' or 'N' then exit the program, otherwise, restart from the beginning.
    /*Simulate a Lotto game using an array of 6 ints for the "official" Lotto numbers drawn,
    an array of 5 ints for the user's Lotto "card", and an array of ints for matched numbers.
    */
    insert
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main (void)
    {srand(time(NULL));
    
    int matchCandidate (int lotto[],unsigned int sizeLotto, int candidate)
    {
    int i = 0;
        for ( i=0; i<sizeLotto; i++)
        {
            if (candidate == lotto[i])
                return (1);
        }
        return 0;
    
    }
    int randomNumberGenerator (int officialNumbers[], unsigned int sizeOfficialNumbers,unsigned int maxNum)
    {
        if (maxNum < sizeOfficialNumbers)
        {
            printf("ERROR:max Number cannot be smaller than the size of the official array\n");
            return 1;
        }
        int currentSize = 0;
        while(currentSize!=sizeOfficialNumbers)
        {
            int candidate = rand() % maxNum +1;
            if(!matchCandidate(officialNumbers,curre…
                officialNumbers [currentSize] = candidate;
                currentSize++;
            }
        }
    return 0;
    }
    int userMatchNumbers (int userNumbers [], int officialNumbers[], unsigned int sizeUserNumbers, unsigned int sizeOfficialNumbers,
                          unsigned int storedNumbers[])
    {
        int i=0;
        unsigned int sizeStoredNumbers = 0;
        for (; i<sizeUserNumbers; i++)
           {
    
        printf("INFO - comparing #%d value %d : ",i,userNumbers[i]);
            if (matchCandidate (officialNumbers, sizeOfficialNumbers, userNumbers[i]))
            {
                printf(" Ok\t");
                storedNumbers [sizeStoredNumbers] = userNumbers[i];
                sizeStoredNumbers ++;
                printf("stored = %d\n",sizeStoredNumbers);
             }
             else{
                printf("Nok\n");
             }
    
           }
           printf("INFO - stored number = ");
           for(i=0;i<sizeStoredNumbers;i++)
                printf("%d",storedNumbers[i]);
            printf("\n");
            return sizeStoredNumbers;

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What's your question?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    25
    Did you get this code above as a starter for your problem? Or, is there code missing from the above quote? It seems to me that this looks like a starter section of a problem that a professor might give; notice the ellipses in line 30; those punctuation marks don't play a role in C that I know of. Several of the lines of code appear to be just cut off or incomplete to the point that they will probably not work as printed above.

    Look at your main function. It looks like a one line procedure that generates a random number. The punctuation on it does not look like it is closing right. Usually there are closing brackets at the end of main; in this case it looks almost like the other functions have been nested inside of main somehow. Is this a typo from cutting and pasting? If main ends after the random number generation, then it's not doing much.

    If main stops where I think it does, that implies that the main and only executed task of the program will be to make that number and then shut the program off. How would the other functions be put to work with main looking like that?

    Look at the other functions. Each performs a task. Yet, how do they get kicked off? What makes the computer use those functions? When or where are they called upon? The functions call on each other, but how does the first one get called? Where does the chain of procedure begin?

    Consider fleshing out that main. Build it up so that it does more than run one line of generating a random number. If you don't, then the program won't do much else but that. Main is where the program begins. Generally speaking, the other functions have to be started somehow; many times, that happens from main. At least the first other function would need to be called from main.

    Maybe it would help to desk check the pattern of functions starting from the initial declarations to main through the functions and back to main. As it is, main does not have a working relationship with those other functions besides just being in the same file with them. Most of the time the cycle of the program will need to start and end with main; that's not absolute, but it's a common practice; we don't see that happening here. A fix might be as simple as including a function by name in main to kick off the rest of the program.
    Last edited by agxphoto; 01-28-2012 at 08:13 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lotto program in c
    By vyshant in forum C Programming
    Replies: 7
    Last Post: 11-07-2011, 11:19 AM
  2. Game Programming Language
    By ??? in forum Game Programming
    Replies: 18
    Last Post: 06-09-2004, 08:39 PM
  3. Lotto problem
    By Roaring_Tiger in forum C Programming
    Replies: 11
    Last Post: 03-13-2003, 09:17 PM
  4. Lotto game in C
    By fun2sas in forum C Programming
    Replies: 2
    Last Post: 03-02-2003, 06:19 PM
  5. Game Programming Language?
    By drdroid in forum Game Programming
    Replies: 62
    Last Post: 09-30-2002, 08:18 AM

Tags for this Thread


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