Lotto C Language game PLEASE HELP

This is a discussion on Lotto C Language game PLEASE HELP within the C Programming forums, part of the General Programming Boards category; When I try to run this it compiles but gives me no output. I'm trying to make a lotto game ...

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

    Lotto C Language game PLEASE HELP

    When I try to run this it compiles but gives me no output. I'm trying to make a lotto game where the user enters 5 numbers between 1 and 47 and those numbers are compared to an array that is randomly filled with 6 numbers between 1 and 47. Then I need to print the numbers that the user chose, state how many matched, and list which ones matched. <-- This last part I don't know how to do. Please help me with this as well as let me know why its compiling with no output. If it helps, I'm using Codeblocks.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <stdbool.h>
    
    
    void main ()
    
    {srand(time(NULL));
    
        int randomNumberGenerator;
        int getLotteryNums;
        int matchCandidate;
        int userMatchNumbers;
        bool rptFunction;
    }
    /*Generates random numbers to fill the official lotto array without repetition.
    lotto is a buffer with unique numbers.
    sizeLotto is the size of the array.
    candidate is a number that will be validated against lotto.
    */
    void 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,currentSize,candidate)){
                officialNumbers [currentSize] = candidate;
                currentSize++;
            }
        }
    return 0;
    }
    //Prompts the user to choose lottery numbers and stores them in an array.
    void getLotteryNums( int userNumbers[5] )
    {
    int i;
    printf("Enter 5 numbers betweeen 1 and 47\n");
    for ( i=0; i<5; i++)
    {
    printf("Enter number %d: ", i+1);
    scanf("%d", &userNumbers[i]);
    }
    }
    
    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 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;
    
    }
    
    bool rptFunction (void)
    {
        char repeatAnswer = 'n';
        printf("Do you want to play again? (n or N for no)\n");
        scanf("%c", &repeatAnswer);
        return (repeatAnswer !='n' || repeatAnswer !='N');
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    void main ()
     
    {srand(time(NULL));
     
        int randomNumberGenerator;
        int getLotteryNums;
        int matchCandidate;
        int userMatchNumbers;
        bool rptFunction;
    }
    It gives you no output because you don't actually call any functions in main.


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

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

    How?

    Quote Originally Posted by quzah View Post
    Code:
    void main ()
     
    {srand(time(NULL));
     
        int randomNumberGenerator;
        int getLotteryNums;
        int matchCandidate;
        int userMatchNumbers;
        bool rptFunction;
    }
    It gives you no output because you don't actually call any functions in main.


    Quzah.
    I'm confused as to how to fix this. Ive been working on this for hours and my brain is fried. How do I call the functions to main?

  4. #4
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    641
    Change Void Main to int main and return 0. You didnt call any functions in main like Quzah stated, You only declared 5 variables, have you learned about functions yet?
    Last edited by camel-man; 01-29-2012 at 09:52 PM.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    2,747
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PLEASE HELP C Language Lotto Game
    By hotshotennis in forum C Programming
    Replies: 2
    Last Post: 01-28-2012, 08:54 AM
  2. assembly language...the best tool for game programming?
    By silk.odyssey in forum Game Programming
    Replies: 50
    Last Post: 06-22-2004, 02:11 PM
  3. Game Programming Language
    By ??? in forum Game Programming
    Replies: 18
    Last Post: 06-09-2004, 09:39 PM
  4. Lotto game in C
    By fun2sas in forum C Programming
    Replies: 2
    Last Post: 03-02-2003, 07:19 PM
  5. Game Programming Language?
    By drdroid in forum Game Programming
    Replies: 62
    Last Post: 09-30-2002, 09: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