Switch command does not work and does not display errors

1

I am trying to solve the following exercise: Elaborate an algorithm that assists in the control of a cattle farm that has a total of 2000 head of cattle. The database is formed by a set of structures (records) containing the following fields for each head of cattle:

• code: cattle code

• milk: number of liters of milk produced per week;

• alim: amount of food eaten per week - in kilograms;

• nasc: date of birth - month and year;

• abate: 'N' (no) or 'S' (yes).

The nasc field. is of the type struct data that in turn, has two fields:

• month

• year

Develop functions for:

a) Read the database (code, milk, food, nasc.man and nasc.ano), stored in a vector of structures.

b) Fill in the slaughter field, considering that the head of cattle will go to slaughter if:

• have more than 5 years, or;

• produce less than 40 liters of milk per week, or

• Produce between 50 and 70 liters of milk per week and ingest more than 50 pounds of food per day.

c) Create the options menu for:

c1.Deliver the total amount of milk produced per week on the farm.

c2. Return the total amount of food consumed per week on the farm.

c3.Deliver the total amount of milk that will be produced per week on the farm after slaughter.

c4. Return the total amount of food that will be consumed per week on the farm after slaughter

c5. Return number of heads of cattle going to slaughter.

c6. Quit the program.

However, I'm having problems with the Switch command, my code is not displaying any messages, either error or warning.

The following is the code below:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>

struct nascimento
{
    int mes;
    int ano;
};

struct registro
{
    int codigo;
    int leite;
    int alimento;
    char abate[2];
    struct nascimento nasc;
};

struct registro gadovet[2];

void registrar_gado(struct registro gadovet[5];)
{
    int i;
    for (i = 0;i < 2; i++)//registro dos 2000 gado
    {
        printf("Digite o código do gado: ");
        scanf("%d", &gadovet[i].codigo);
        printf("Digite a quantidade de leite que o gado fornece por semana - em litros: ");
        scanf("%d", &gadovet[i].leite);
        printf("Digite a quantidade de alimento ingerida por semana - em quilos: ");
        scanf("%d", &gadovet[i].alimento);
        printf("Digite a data de nascimento do gado\n");
        printf("Mês: ");
        scanf("%d", &gadovet[i].nasc.mes);
        printf("Ano: ");
        scanf("%d", &gadovet[i].nasc.ano);

        //verificação de abate
        if (gadovet[i].leite >= 50 && gadovet[i].leite <= 70 && gadovet[i].alimento > 50)
        {
            if (gadovet[i].nasc.ano < 2013 || gadovet[i].leite < 40)
            {
                strcpy (gadovet[i].abate, "S");
            }
            else
            {
                strcpy (gadovet[i].abate, "N");
            }
        }
        if (gadovet[i].nasc.ano > 2013 || gadovet[i].leite > 40)
            {
                strcpy (gadovet[i].abate, "N");
            }
    }
}

int main()
{
    setlocale(LC_ALL,"Portuguese");
    int i, x = 0, n = 0, abate = 0;
    char sim[2] = {"S"};
    char nao[2] = {"N"};

    registrar_gado(gadovet[2]);

    do//Menu
    {
        printf("Escolha uma das opções:");
        printf("\n1 - Verificar a quantidade total de leite produzida por semana na fazenda.");
        printf("\n2 - Verificar a quantidade total de alimento consumido por semana na fazenda.");
        printf("\n3 - Verificar a quantidade total de leite que vai ser produzido por semana na fazenda, após o abate.");
        printf("\n4 - Verificar a quantidade total de alimento que vai ser consumido por semana na fazenda, após o abate.");
        printf("\n5 - Verificar o número de cabeças de gado que iram para o abate.\n\n");
        scanf("%d", &n);

    }while(n = 0);

    switch (n)
    {
        case 1://Leite por semana
            for (i = 0;i < 2; i++)
            {
                x = x + gadovet[i].leite;
            }
            printf("A quantidade de leite que o todo o gado oferece por semana é de %d Litros.", x);
            break;
        case 2://Alimento por semana
            for (i = 0;i < 2; i++)
            {
                x = x + gadovet[i].alimento;
            }
            printf("A quantidade de alimento que o todo o gado consome por semana é de %d Quilos.", x);
            break;
        case 3://Leite após abate
            for (i = 0;i < 2; i++)
            {
                if (!strcmp(gadovet[i].abate, nao))
                {
                    x = x + gadovet[i].leite;
                }
            }
            printf("A quantidade de Leite que será consumido por semana após o abate será de %d Litros.", x);
            break;
        case 4://Alimento após abate
            for (i = 0;i < 2; i++)
            {
                if (strcmp(gadovet[i].abate, nao))
                {
                    x = x + gadovet[i].alimento;
                }
            }
            printf("A quantidade de Alimento que será consumido por semana após o abate será de %d Quilos.", x);
            break;
        case 5://Cabeças pro abate
            for (i = 0;i < 2; i++)
            {
                if (!strcmp(gadovet[i].abate, sim))
                {
                    abate++;
                }
            }
            printf("A quantidade de cabeças que irão para o abate é de %d", abate);
            break;
        case 6:
            printf("Pressione qualquer tecla para sair...");
            system("Pause");
            break;
    }
}
    
asked by anonymous 12.05.2018 / 02:57

1 answer

2

In the line where the do...while command is, the condition is as n = 0 , try to trade n == 0 .

    
12.05.2018 / 03:02