0
How can I generate some (detail: plural) random cards with numbers, but need to manipulate them as a three-dimensional matrix. Cartela[players] [n] [n] .. n = The dimension
My program generates only one card, how can I generate more cards ? The chart index will be defined in the players variable, which 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;
}
From what I understand in place of
int cartela[n][n];
utilizeint cartela[jogadores][n][n];
and in each reference tocartela
use 3 indexes, the first being the player.– anonimo