Lotto game in C

This is a discussion on Lotto game in C within the C Programming forums, part of the General Programming Boards category; For our homework, we have to write a program that simulates a lottery, randomly drawing 3 balls numbered 1 through ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    2

    Lotto game in C

    For our homework, we have to write a program that simulates a lottery, randomly drawing 3 balls numbered 1 through 10. The user inputs the # of drawings. What I don't get is how to show the percentage of times the number(s)drawn are 7, 1 2 & 3, or even numbers. Can anyone give me any suggestions on how to do counters to show these percentages. This code works except for doing the percentages.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    main()
    {
         unsigned int seed;
         int a=1, b=10, k;
         int rand_int(int a, int b);
         int numDraw;
    	
         printf("Enter number of Lottery Drawings to simulate:  ");
         scanf("%i", &numDraw);
    
         printf("\nEnter a positive integer seed value: ");
         scanf("%u",&seed);
         srand(seed);
    
         while (numDraw > 0)
         {
              for (k=1; k<=3; k++)
              {
                    printf("%i  ",rand_int(a,b));
              }
              printf("\n");
              numDraw--;
         }
    return 0;
    }
       
    int rand_int (int a, int b)
    {
         return rand()%(b-a+1) + a;
    }
    Last edited by fun2sas; 03-02-2003 at 06:07 PM.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    2

    Lotto Game

    Sorry!- Never done this before. Hope it's okay now!

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>What I don't get is how to show the percentage of times the number(s)drawn are 7, 1 2 & 3, or even numbers.
    You know how to do it on paper? You need to record the occurences of each number, and the total number of draws, then do some simple maths to get the percentages.

    The easiest way to keep track of the occurences is to use an array, the same size as the number of different balls.
    >>int History[10] = {0};
    There, that should get you started... have a go and see what you can come up with. Post again when you have problems.

    General comments:

    >>main()
    is normally declared:
    >>int main(void)

    >>for (k=1; k<=3; k++)
    In general loops in C go from 0 to N-1, so in your code that would be:
    >>for (k=0; k<3; k++)
    It still runs 3 times, but the format is a convention for C programmers. No point in breaking it unless you have a reason to.

    At some point, you might want to improve your number reading routine too.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-07-2010, 11:08 PM
  2. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 02:46 PM
  3. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  4. C++ Game of Life Program
    By rayrayj52 in forum C++ Programming
    Replies: 16
    Last Post: 09-26-2004, 03:58 PM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM

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