mardi 16 février 2021

BINGO GAME in C , MATRIX WITH 3 Dimensions?

How can I generate some random cards with numbers, but I need manipulate them as a 3 dimenson matrix . [players][n][n] .. n = The dimenson

My program generates only one card, how can I generate more cards? The index of the cards will be set in the variable players( jogadores in the program) that is the first dimension of the Matrix

#include<stdio.h>
#include<stdlib.h>
int n, soma;
int jogadores;
int menu;
int main ()
{
srand(123);

printf("Número de jogadores: \n");
do
{
    scanf("%d",&jogadores);

} while (jogadores < 2 || jogadores > 10);


printf("Numero de jogadores salvo \n Escolha a dimensao das cartelas: \n");
do
{
    scanf("%d",&n);

} while (n < 2 || n > 9);

printf("\n Dimensao das cartelas salva \n ");

//printf(" %d %d \n ",jogadores,n);

int value = 10*n;

int cartela[n][n]; // I need to add the dimensiona _jogadores_ ==> cartela [jogadores][n][n]

  //for (int q = 0; q <=jogadores;q++) // Loop number of players  
    //{
      for(int i = 0; i <= n; i++) // Loop lines of the card
      {
        for (int j = 0; j < n; j++) // Loop rows of the card
        {
          do
            {
               soma = 0;
               cartela[i][j] = rand()%value; // Colocar a dimensão jogadores

           
               for (int l = 0; l < n; l++)
                {
                  for (int c = 0; c < n; c++)
                  {
                    if(cartela[i][j] == cartela[l][c] && (i!= l && j!= c))
                    {
                        soma++;
                    }
                  }
                
                }
            
            } while (soma != 0);  
            
         }
      }


   // for (int  j = 0; j < jogadores; j++)
    //{
        for (int l = 0;l<n;l++)
          {
       for(int c=0;c<n;c++)
        {
          printf("\t %d",cartela[l][c]);
        }
          printf("\n");
        }
    //}
    
    
   

//while(1)
//{




//}
    

return 0;
}

That's my code, and like I said before, the biggest question is how can i use the 3 dimension matrix to get more cards.




Aucun commentaire:

Enregistrer un commentaire