1
I need to create an algorithm as requested below, but every time I run the program it "skips" steps. For example:
I want you to stay like this
Product: "Potato"
Sector: "Food"
Quantity: "15"
Price: "15.23"
But it prints on the screen and ignores the scanf
Down with the exercise
Be an algorithm to control the stock products of a supermarket. To each product has the following fields:
- Name: string size 15.
 - Sector: character
 - Quantity: integer
 - Price: real //price per unit of product
 
a) Write definition of the product structure
b) Declare the stock vector of the above defined structure type, size 100 and overall.
c) Create a menu for:
C1. Set a block of instructions to read the stock vector.
C2.Define an instruction block that receives a sector and return the number of different products in that sector.
C3. Define a block of instructions that calculates and returns the total capital invested in supermarket products.
C4.Exit from the Program.
//Controle Estoque de produtos de Supermercado
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
struct produto
{
    char nome[15];
    char setor[15];
    int quantidade;
    float preco;
};
struct produto prod[2];
int estoque(struct produto prod[2];)
{
    int i;
    for (i = 0;i < 2; i++)
    {
        printf("\nDigite o nome do produto: ");
        scanf("%s", &prod[i].nome);
        printf("\nDigite o setor: ");
        scanf("%c", &prod[i].setor);
        printf("\nDigite a quantidade: ");
        scanf("%d", &prod[i].quantidade);
        printf("\nDigite o preço: ");
        scanf("%f", &prod[i].preco);
    }
}
int verificar_setor(struct produto prod[2];)
{
    int i, p = 0;
    char ver[15];
    printf("\nDigite o setor: ");
    scanf("%c", &ver);
    for (i = 0;i < 2; i++)
    {
        if (strcpy(ver,prod[i].setor))
        {
            p++;
        }
    }
    printf("Existem %d produtos cadastrados neste setor.", p);
}
int capital(struct produto prod[2];)
{
    int i;
    float c = 0.0;
    for (i = 0;i < 2; i++)
    {
        c = c + prod[i].preco;
    }
    printf("Foi investido um total de %2.f Reais em produtos no Supermercado.", c);
}
int main()
{
    setlocale(LC_ALL,"Portuguese");
    int n = 0;
    printf("Escolha uma opção");
    do
    {
        printf("\n1 - Cadastrar produtos.");
        printf("\n2 - Verificar quantos produtos existem em um determinado setor.");
        printf("\n3 - Total de capital investido nos produtos do Supermecado.");
        printf("\n4 - Sair do Programa.\n");
        scanf("%d", &n);
        switch (n)
        {
            case 1:
                estoque(prod[2]);
                n = 0;
                break;
            case 2:
                verificar_setor(prod[2]);
                n = 0;
                break;
            case 3:
                capital(prod[2]);
                n = 0;
                break;
            case 4:
                printf("Pressione qualquer tecla para sair...");
                system("Pause");
                break;
        }
    }while (n == 0);
    return 0;
}
						