My goal in this exercise is that in each loop to make a new snack request, the reported data is appended to the final table (array [i] [j]). In the second "for" is where I try to assign the variables [int cod] [char snack] [int price] into the array. I believe there is an incompatibility of variables, but even replacing the variables with "text" continues to go wrong. In short, I need help identifying the error and if possible, give me an alternative to resolve the incompatibility between the array and the variables I want to put in it. I thank you all. (my first question here on Stack the /).
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;
}