# Thread: Lotto game in C

1. ## 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;
}``` 2. ## Lotto Game

Sorry!- Never done this before. Hope it's okay now! 3. >>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 = {0};
There, that should get you started... have a go and see what you can come up with. Post again when you have problems.

>>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. Popular pages Recent additions 