how are you? I'm having difficulty designing a program and would like to know if you can help me with it. The work is about making a product registration system for a company. To explain better, some things I was able to do:
- I created the struct of the products with name, value and we chose flavor and filling as the characteristics
- I created a void main menu with 4 possibilities (the 3 described in the work + 1 to terminate the program)
- I created a void with return for the user's choice of possibilities
- I created the void registration based on the struct product, but I'm not able to find a way to repeat it without setting a value for the for; however, I didn't want to have set a repeat value.
After that, this would be my question:
- How to print the table of products that the customer registered with two characteristics together (flavor and filling).
Thank you in advance for any help, opinion and criticism.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct produto
{
char nome[30];
float valor;
int sabor;
int recheio;
};
void menu_principal()
{
printf("\t\t\tMENU PRINCIPAL");
printf("\n1: Digite 1 para incluir um produto");
printf("\n2: Digite 2 para imprimir a lista de produtos");
printf("\n3: Digite 3 para consultar o valor de um produto");
printf("\n4: Digite 4 para encerrar o programa");
}
void menu_escolha(char *escolha)
{
printf("\nDigite sua escolha: ");
scanf(" %c", &(*escolha));
}
void cadastro(struct produto p[])
{
int i, quant = 0;
printf("\t\t\tCADASTRO DE PRODUTO");
printf("\nQuantos produtos voce ira cadastrar? ");
scanf("%d", &quant);
for(i = 0; i < quant; i++)
{
fflush(stdin);
printf("\nNome do produto %d: ", i + 1);
gets(p[i].nome);
do
{
fflush(stdin);
printf("Sabor do produto %d (1: doce / 2: salgado): ", i + 1);
scanf("%d", &p[i].sabor);
}
while(p[i].sabor < 1 || p[i].sabor > 2);
do
{
fflush(stdin);
printf("Recheio do produto %d (1: chocolate / 2: baunilha / 3: frango / 4: carne): ", i + 1);
scanf("%d", &p[i].recheio);
}
while(p[i].recheio < 1 || p[i].recheio > 4);
do
{
fflush(stdin);
printf("Valor do produto %d (ex.: 1.23): ", i + 1);
scanf("%f", &p[i].valor);
}
while(p[i].valor < 0);
}
}
void impressao_sabor(struct produto p[], int tipo_um)
{
int i;
for(i = 0; i < 30; i++)
{
if(p[i].sabor == tipo_um)
{
printf("\nNome do produto : %s", p[i].nome);
printf("\nSabor do produto : %d", p[i].sabor);
printf("\nRecheio do produto : %d", p[i].recheio);
}
}
printf("\n");
}
void impressao_recheio(struct produto p[], int tipo_dois)
{
int i;
for(i = 0; i < 3; i++)
{
if(p[i].recheio == tipo_dois)
{
printf("Nome do produto %d: %s", i+1, p[i].nome);
printf("Sabor do produto %d: %d", i+1, p[i].sabor);
printf("Recheio do produto %d: %d", i+1, p[i].recheio);
}
}
printf("\n");
}
void main()
{
struct produto p[30];
char escolha;
char decisao;
menu_principal();
menu_escolha(&escolha);
switch(escolha)
{
case '1':
cadastro(p);
printf("\nAdicionar mais um produto? s/n: ");
scanf(" %c", &decisao);
printf("\n");
do
{
if(decisao == 's')
{
cadastro(p);
printf("\nAdicionar mais um produto? s/n: ");
scanf(" %c", &decisao);
printf("\n");
}
}
while(decisao == 's');
if(decisao == 'n')
{
menu_principal();
menu_escolha(&escolha);
}
case '2':
printf("\t\t\tLISTA DOS PRODUTOS");
printf("\nSabores dos produtos");
printf("\nDoce");
impressao_sabor(p,1);
printf("\nSalgado");
impressao_sabor(p,2);
;
case '3':
//consulta(p);
//menu_principal();
break;
case '4':
printf("\nObrigada por usar o programa!");
break;
default:
printf("Opcao invalida!");
menu_escolha(&escolha);
}
}