As of right now I have my code reading from a .txt file with peoples names & there six chosen lottery numbers.
My code ask for the file, and the winning numbers and stores the winning numbers in an array called win_nums.
Here is where I need help. I now need to compare the winning numbers with all the peoples numbers in the .txt file. There will be someone who matches 3 numbers, 4 numbers, 5 numbers, and all 6. If someone matches with 3 they win $10 & the program prints out "first last matched 3 numbers and won $10.", 4 matches $100, 5 matches $10000, & 6 $1000000.
If someone could help me with the code it would be greatly appreciated it.
Here is my code as of now:
Code:
#include <stdio.h>
typedef struct {
char last[25];
char first[25];
int player_nums[6];
}LOTTO, *LPLOTTO;
int main() {
//initialize variables.
char input[50];
int index, win_nums[6];
//prompt user for file.
printf("Enter the name of the file with the ticket data:\n");
scanf("%s", input);
printf("\n");
//prompt user for winning lottery numbers.
printf("Enter the winning Lottery numbers:\n");
for (index=0; index < 6; index++)
scanf("%d", &win_nums[index]);
printf("\n");
//Record tickets from file.
int num_tix, i, j;
LPLOTTO people;
FILE *ifp = fopen(input, "r");
if (ifp==0) return -1;
fscanf(ifp,"%d",&num_tix);
people = (LPLOTTO)malloc(sizeof(LOTTO)*num_tix);
for (i=0; i<num_tix; i++) {
fscanf(ifp, "%s %s", people[i].last, people[i].first);
for (j=0;j<6;j++)
fscanf(ifp, "%d", people[i].player_nums+j);
}
//close users file.
fclose(ifp);
system("PAUSE");
return 0;
}
Thank you very much!