Results 1 to 2 of 2

Thread: Help in generating random numbers!!!

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1

    Help in generating random numbers!!!

    Actually the aim of the game is, six numbers are generated between 1-40 and a player can bet six numbers between 1-40.
    If the player get all the six numbers correct he wins the jackpot. Each bet costs Rs 20
    Thus In the program below i want to create codes such that:
    a bet costs Rs 20 and a player can play as many times as he wishes for each draw.
    Then the program should display the bet and the total bet.


    Code:
    #include 
    #include 
    
    void fCompare(int userNumbers[6]);
    
    int main()
    {
    
        int userNumbers[] = {0,0,0,0,0,0};
        
        printf("Please bet 6 numbers in the range 1-40: ");
        scanf("%d %d %d %d %d %d",&userNumbers[0],&userNumbers[1],&userNumbers[2],&userNumbers[3],&userNumbers[4],&userNumbers[5]);
        printf("\n");
        fCompare(userNumbers);
    
        system ("PAUSE");
        return 0 ;
    }
    
    void fCompare(int userNumbers[6])
    {
        int i = 0;
        int true = 1;
        int correct = 0;
        for(i = 0; i < 6; i++)
        {
            if(userNumbers[i] == true ) correct++;
        }
        if (correct == 6) //do something
            printf("God is good");
    }

  2. #2
    Junior Member
    Join Date
    Sep 2010
    Posts
    13
    Hi,

    You can use the function rand() which should be included from stdlib.h library.
    This function generates a random number. You can use % (modulus operator) to range your random number from 1 to 40.

    You can set the seed for the random function by using srand(seed) function.

    I hope this answered your question.

    All the best

    David

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •