I am making a program to simulate the lotto. The numbers can range between 1-45, but the numbers drawn must be unique. The program generates 6 random numbers in this range and adds them to an array. The user enters their numbers and the program checks if the 2 arrays are the same i.e whether they have won the lotto or not.
I don't know why, but my program doesn't generate the random numbers, nor does it check if they're equal.
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, const char * argv[]) {
> // insert code here...
> int lotto[6];
> int i;
>
> int user[6];
> for(i=0; i<6; i++){
> printf("Please enter a number between 1 and 45: \n");
> scanf("%d", &user[i]);
> }
> printf("User's numbers: \n");
> for(i=0; i<6; i++){
> printf("%d \n", user[i]);
> }
> printf("Generate 6 Random Lotto Numbers \n");
>
>
> for(i=0; i<6;i++){
> lotto[i] = rand() % 46 + 1;
> scanf("%d", &lotto[i]);
> }
> for(i=0; i<6; i++){
> printf("%d \n",lotto[i]);
> }
>
>
>
>
> for(i=0; i<6; i++){
> if(lotto[i] != user[i]){
> printf("Hard luck. Try again next time.");
> break;
> }
> else{
> printf("You've won the lotto!");
> }
>
> }
> return 0; }
Any help would be extremely helpful and I'd be even more grateful. :)
Aucun commentaire:
Enregistrer un commentaire