# Arrays making a lotto programme

• 11-16-2012
flysurfer
Arrays making a lotto programme
this is an array question we were asked to fiddle with and figure out in our spare time he said he will give the solution monday but I cant wait because ive been struggling with arrays and want to try and understand this if any one can help me please.
Given the following 3 array definitions:
int lotto7 = 3, 19, 4, 20, 21, 41, 26;
int lotto_plus1 7 = 13, 11, 14, 33, 21, 36, 17;
int lotto_plus2 7 = 40, 17, 14, 21, 35, 32, 30;

You are required to write a program to ask the user to enter in their 6 lotto
numbers.
The program is to check the results for each of the 3 arrays above. The 7th number is the bonus number in each of the arrays above.
Check the user numbers against each of the lotto arrays to see if the users has won any prizes:
Winning combinations:
- Match all 6 numbers with user numbers – wins jackpot
-
Match any 5 numbers with any 5 user numbers – wins cash prize
-
Match any 4 numbers with any 4 user numbers – wins cash prize
-
Match any 5 numbers and the bonus number with 6 user numbers – wins cash prize
-
Match any 4 numbers and the bonus number with any 5 user numbers – wins cash prize
-
Match any 3 numbers and bonus number with any 4 user numbers – wins a cash prize
- Match any 3 numbers wins lottery scratch card
- None of the above - not a winner

The program is to display the results of each lotto array check to the user.
• 11-16-2012
thames
• 11-16-2012
flysurfer
Code:

```#include <stdio.h> int main() {  int lotto[7] = {3, 19, 4, 20, 21, 41, 6};  int lotto_plus1[7] = {13, 11, 14, 33, 21, 36, 16};  int lotto_plus2[7] = {40, 17, 14, 21, 35, 32, 30};  int mynumbers[6], i, j, num_matches = 0;  int bonus = 0;                // bool bonus = false;  // possible range of entry is 1 to 45  for(i = 0; i < 6; i++)  {   do   {   printf("Enter your lotto number %d\n", i + 1);   scanf("%d", &mynumbers[i]);   }   while(mynumbers[i] <= 0 || mynumbers[i] >= 46);  } // check lotto results here. // bonus number will be at position 6 // check mynumbers against bonus number in each draw   for(i = 0; i < 6; i++)   {     if(mynumbers[i] == lotto[6])  // lotto[6] has bonus number         bonus = 1;        // bonus = true;   } return 0; }```
sorry here it is its not much :/
• 11-16-2012
Matticus
That's a pretty good start.

You might want to consider using nested loops to achieve the results.

You need to develop an algorithm. Work it out on paper to figure out the logic before coding. One way to approach it might be like so:

Code:

```declare a match counter (initialize to zero) compare the first user number to the first set of winning numbers if a match is found, increment the match counter compare the second user number to the first set of winning numbers if a match is found, increment the match counter etc```
This is by no means comprehensive, but merely to illustrate how you should think about the problem in order to solve it.
• 11-16-2012
flysurfer
thanks very much il try that :)

im sorry but i don't understand what you mean by algorithm?
• 11-16-2012
thames
You can use two for's to make the comparison and counters to count how many times you scored.

Code:

```     #ifndef  SIZEMYLOTTO     #define  SIZEMYLOTTO 6   #endif  #ifndef SIZELOTTO7   #define SIZELOTTO7  7  #endif   int lotto7Comparison(int myLotto[], int lotto7[])   {     int i, j, scored;     scored = 0;     for(i = 0; i < SIZEMYLOTTO; i++)       for(j = 0; j < SIZELOTTO; j++)       {           if(myLotto[i] == lotto7[j])           scored++;       }       return scored;    } int main(void) {   int myLotto[SIZEMYLOTTO];   int lotto7[SIZELOTTO7];   .   .   .   if(lotto7Comparison(myLotto, lotto7) == 7 )     printf("jackpot!");   if(lotto7Comparison(myLotto, lotto7) == 6)     .     .     .   return 0; }```
the two for's ensure that every single number of your lotto is going to be compared with all the numbers of lotto7.

also, please take the habit to write

Code:

``` int main(void) {   return 0; }```
``` int main() {   return 0; }```