-2
My objective in this exercise is that in each loop to make a new snack order, the informed data be added in the final table (matrix[i][j]). In the second "for" is where I try to assign the variables [int Cod] [char lanche] [int preco] into the matrix. I believe that there is an incompatibility of variables, but even replacing the variables with "text" still goes wrong. In short, I need help to identify the error and if possible, indicate me an alternative to solve the incompatibility between the matrix and the variables I want to put in it. Thanks already to everyone. (my first question here at the Stack/).
int main(int argc, char *argv[]) {
setlocale(LC_ALL, "Portuguese");
int cod, preco, total, quant, cont, i, j;
char lanche[100], matriz[i][j], novo_pedido;
total=0;
cont=1;
for(i=0; i<cont; i++){          
            puts("+--------+-------------------+----------------+");
            puts("| Código |      Lanche       |   Preço Unit.  |");
            puts("+--------+-------------------+----------------+");
            puts("|  100   |  Cachorro Quente  |    R$ 5,00     |");
            puts("|  101   |  Bauru Simples    |    R$ 6,00     |");
            puts("|  102   |  Bauru com Ovo    |    R$ 8,00     |");
            puts("|  103   |  Hamburguer       |    R$ 5,00     |");
            puts("|  104   |  Cheeseburger     |    R$ 7,00     |");
            puts("|  105   |  Refrigerante     |    R$ 2,00     |");
            puts("+--------+-------------------+----------------+");
            puts("\n\n+---------------Faça seu Pedido---------------+");
            cod=1;
            do{
            printf("Código do Lanche: ");
            scanf("%d", &cod);
                if(cod==100){
                    total=(total+5);
                    strcpy(lanche,"Cachorro Quente  ");
                }else if(cod==101){
                    total=(total+6);
                    strcpy(lanche,"Bauru Simples    ");
                }else if(cod==102){
                    total=(total+8);
                    strcpy(lanche,"Bauru com Ovo    ");
                }else if(cod==103){
                    total=(total+5);
                    strcpy(lanche,"Hamburguer       ");
                }else if(cod==104){
                    total=(total+7);
                    strcpy(lanche,"Cheeseburger     ");
                }else if(cod==105){
                    total=(total+2);
                    strcpy(lanche,"Refrigerante     ");
                }else{
                    puts("\n**Código Inválido!**\n");
                }
            }while ((cod<100)||(cod>105));
            printf("Quantidade: ");
            scanf("%d", &quant); getchar();
            puts("+---------------------------------------------+");
    for(j=0; j<3; j++){
        if(j==0){
            matriz[i][j]="cod";
        }
        if(j==1){
            matriz[i][j]="lanche";
        }
        if(j==2){
            matriz[i][j]="preco";
        }
    }       
            printf("Deseja realizar outro pedido? ");
            fflush(stdin);
            novo_pedido=getchar();
                if(novo_pedido=='s'){
                    cont=cont+1;
                    system("cls");
                }
            puts("+---------------------------------------------+");
            puts("");
}
        puts("\n\n+-------------Resultado do Pedido-------------+");
        puts("| Código |      Lanche       |  Quantidade"); 
for (i=0; i<cont; i++){
    for (j=0; j<3; j++){        
        //printf("|   %d  |  %s|     %d\n", cod, lanche, quant);
        printf("%s", matriz[i][j]);
    }
}
        puts("+---------------------------------------------+");
        printf("|                     TOTAL  |   R$ %d,00", (total*quant));
        puts("\n+---------------------------------------------+\n");
return 0;
}
						
How you have such a big code if at first you have an error?
matriz[i][j]cannot define a matrix with variables.– Fábio Morais
Need to indicate if you want to do with static memory
matriz[100][100]or dynamic memory**matrizthen using memory allocation– Fábio Morais
I was just reusing a code from an exercise to test the use of matrices and vectors, but in my course I didn’t even get to this subject yet so I’m studying on my own. Thank you so much for the help, if you can fix it I put the result.
– Lucas Tovo
I can’t help because I still don’t understand much of what you want. Have you learned about dynamic memory? Can I store the quantity and code in a vector and the product in a matrix? Putting everything in a matrix would be more complicated
– Fábio Morais
i managed, using only vectors and pointers, another haha implemento matrices hr.
– Lucas Tovo