-This is what I have so far. I was wondering if someone could help me finish is up. I need the user to enter 5 numbers and match theirs with the 6 random numbers that were generated in the lotto game. Then, I need to display the numbers that the user chose along with the numbers that matched that of the official lotto numbers. And then I need to prompt the user and ask if they want to play again. If they answer either 'n' or 'N' then exit the program, otherwise, restart from the beginning.
/*Simulate a Lotto game using an array of 6 ints for the "official" Lotto numbers drawn,
an array of 5 ints for the user's Lotto "card", and an array of ints for matched numbers.
*/
insert
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (void)
{srand(time(NULL));
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 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,curre…
officialNumbers [currentSize] = candidate;
currentSize++;
}
}
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;