Lottery game program using matrix

Asked

Viewed 734 times

0

I need to make a program in C, that the user enters with 5 games of 6 dozens stored in a 5x6 matrix. I need to create a function that draws a game of six dozens stored in a vector of 6 positions and another function that checks if the user hit 2 numbers.

I couldn’t just do the function of checking the games.

#include <stdio.h>  
#include <stdlib.h>
#include <time.h>
#include <conio.h>

#define T 6 //quantidade de dezenas sorteadas
#define VALIDO   1
#define INVALIDO 0
#define C 6 //numero de colunas
#define L 2 //numero de linhas

    insira o código aqui

<void menu();
<void jogar();
void sortear();
void conferirSorteio();

int matriz[L][C];
int opc = 0;
int sorteio[T];

int main()
{
    while(opc !=4)
    {
        menu();
        switch(opc)
        {
        case 1:
            jogar();
            printf("\nConcluido.\nPressione qualquer tecla para continuar...");
            getch();
            system("cls");
            break;
        case 2:
            sortear();
            printf("\nConcluido.\nPressione qualquer tecla para continuar...");
            getch();
            system("cls");
            break;
        case 3:
            conferirSorteio();
            printf("\nConcluido.\nPressione qualquer tecla para continuar...");
            getch();
            system("cls");
            break;
        }
    }

    return 0;
}

void menu()
{
    printf("1 - Jogar\n");
    printf("2 - Sortear\n");
    printf("3 - Conferir Resultado\n");
    printf("4 - Sair\n");
    printf("Digite a sua opcao: ");
    scanf("%d", &opc);
}

void jogar(){

    int i, j;

    /*Lendo todos os elementos da matriz.*/
    for(i=0; i<L; i++){
        printf("\nDigite os numeros da cartela %d: \n", i+1);
        for(j=0; j<C; j++)
            scanf("%d", &matriz[i][j]);
           }

    /*Imprimindo a matriz.*/
    printf("\nListando as cartelas de jogos .");
    for(i=0; i<L; i++){
        printf("\n\nLinha %d:\n", i+1);
        for(j=0; j<C; j++)
            printf("%d ", matriz[i][j]);
           }

}

void sortear(){
    int i, j;
    int status, aux;

    srand((unsigned)time(NULL));

    for(i=0; i<T; i++){
        do{
        sorteio[i]= 1 + rand() % 60;
        status = VALIDO;
        for (j = 0; j < i; ++j)
            if (sorteio[i] == sorteio[j])
            status = INVALIDO;
       }while (status == INVALIDO);

   }
   for(i=0; i<T; i++){
     for(j=i+1; j<T; j++){
        if(sorteio[i]>sorteio[j]){
            aux=sorteio[i];
            sorteio[i]=sorteio[j];
            sorteio[j]=aux;
        }
    }
}

    printf("\n\nSeis dezenas sorteadas\n");
    for(i=0; i<T; i++){
        printf("|%d", sorteio[i]);
    }
    printf("\n");
}

    void conferirSorteio(){
    int i, j, k;
    int conferir;
    int pontos = 0;

    //confere o numeros de acertos
    for(i=0; i<L; i++){
        for(j=0; j<C; j++){
            conferir = matriz[i][j];
            for(k=0; k<C; k++){
                if(sorteio[k] == conferir){
                    pontos++;
                    }
                }
            }
        }

    if(pontos==2){
        printf("Parabens voce fez 2 ou mais pontos!");
         }else{
        printf("Que pena voce fez menos de 2 pontos!");
         }
}
  • Put the missing code so that it is possible to test and reproduce the problem. What should do the function conferir ? Receive two numbers and see if they exist in matriz ?

  • Adriano, select the code and press <Ctrl> + <k>, this will make it properly formatted as a code block and therefore readable

  • sorry, vlw thank you!!

  • There was not a flaw in the placement of the code ? Now look at this part -> insira o código aqui <void menu(); <void jogar();. And you still haven’t answered the previous question I asked -> "What should the function check ? Receive two numbers and see if they exist in matrix ?"

  • I had to leave. the check function should check if I hit 2 numbers in one of the 5 games.

  • The program must receive 5 user games with 6 dozens. And generate a game to check whether hit 2 numbers.

  • I think now everything is ok.... I’m sorry!!!

  • I made a function void conferirSorteio() but it cannot separate the numbers of hits for each game....

  • The draw is to be analyzed in how many cards ? all?

  • 5 packs, matrix 5x6.

  • have to check all the cards and check how many got 2 numbers.

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.