Thread: Lotto C Language game PLEASE HELP

  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
    693
    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
    4,183
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

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, 01:11 PM
  3. Game Programming Language
    By ??? in forum Game Programming
    Replies: 18
    Last Post: 06-09-2004, 08: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, 08:18 AM

Tags for this Thread