When I try to run this it compiles but gives me no output. I'm trying to make a lotto game where the user enters 5 numbers between 1 and 47 and those numbers are compared to an array that is randomly filled with 6 numbers between 1 and 47. Then I need to print the numbers that the user chose, state how many matched, and list which ones matched. <-- This last part I don't know how to do. Please help me with this as well as let me know why its compiling with no output. If it helps, I'm using Codeblocks.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
void main ()
{srand(time(NULL));
int randomNumberGenerator;
int getLotteryNums;
int matchCandidate;
int userMatchNumbers;
bool rptFunction;
}
/*Generates random numbers to fill the official lotto array without repetition.
lotto is a buffer with unique numbers.
sizeLotto is the size of the array.
candidate is a number that will be validated against lotto.
*/
void 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,currentSize,candidate)){
officialNumbers [currentSize] = candidate;
currentSize++;
}
}
return 0;
}
//Prompts the user to choose lottery numbers and stores them in an array.
void getLotteryNums( int userNumbers[5] )
{
int i;
printf("Enter 5 numbers betweeen 1 and 47\n");
for ( i=0; i<5; i++)
{
printf("Enter number %d: ", i+1);
scanf("%d", &userNumbers[i]);
}
}
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 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;
}
bool rptFunction (void)
{
char repeatAnswer = 'n';
printf("Do you want to play again? (n or N for no)\n");
scanf("%c", &repeatAnswer);
return (repeatAnswer !='n' || repeatAnswer !='N');
}