#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int
smallest_element(
int
*set,
int
length,
int
skip);
void
sort(
int
*list,
int
length);
int
i,j,k;
int
A[6];
int
B[6];
int
main(){
printf
(
"Welcome to The 6/49 Lotto Game\n"
);
printf
(
"Enter 6 numbers between 1 and 49 and have a chance to winn:\n"
);
for
(i=0;i<6;i++){
scanf
(
"%d"
,&B[i]);
if
(B[i]>49){
printf
(
"Please enter a number between 1 and 49\n"
);
i--;
continue
;
}
}
sort(B,6);
srand
(
time
(NULL));;
for
(j=0;j<6;j++){
A[j]=1+
rand
()%49;
for
(k=0;k<=j-1;k++){
if
(A[j]==A[k]){
break
;
}
}
if
(k==j){
continue
;
}
else
{
j--;
}
}
sort(A,6);
printf
(
"This weeks winning numbers are: \n"
);
printf
(
"%d\n%d\n%d\n%d\n%d\n%d\n"
,A[0],A[1],A[2],A[3],A[4],A[5]);
if
(A==B){
printf
(
"Congratulations! You WIN!\n"
);
}
else
{
printf
(
"I'm sorry. You LOST. Try again next week.\n"
);
}
return
0;
}
int
smallest_element(
int
*set,
int
length,
int
skip){
int
smallest_index;
int
i;
smallest_index=skip;
for
(i=skip+1;i<length;i++){
if
(set[i]<set[smallest_index]){
smallest_index=i;
}
}
return
smallest_index;
}
void
sort(
int
*list,
int
length){
int
i,j;
int
temp;
for
(i=0;i<length-1;i++){
j=smallest_element(list,length,i);
temp=list[i];
list[i]=list[j];
list[j]=temp;
}
}