I’m a beginner in C, I need help on a task!

Asked

Viewed 92 times

-1

The statement says: 1. Knowing that a company has 20 employees, make a program that reads the salary and sex of each employee and report how many employees earn more than R $ 1.000,00 and how many women earn more than R $ 5.000,00. Report even the lowest and highest salary and average wage among men and women.

So far I’ve done the following:


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

int main (void)

{
    int quant_mais1000,quant_H,quant_M,mulher_mais5000,soma_H,soma_M;
    float salario,menor,maior,mediaH,mediaM;
    char sexo;

    for(int i=1;i<=20;i++){

        printf("Insira o salario: ");
        scanf("%f",&salario);

        printf("Insira o sexo: ");      
        scanf("\n%c",&sexo);

        if(i=1){
            maior=salario;
            menor=salario;
        }

        if (salario>=100){
            quant_mais1000++;
        }

        if(sexo == 'M' || sexo == 'm'){

            soma_H=soma_H+salario;
            quant_H++;          
        }


        if(sexo == 'F' || sexo == 'f'){

            soma_M=soma_M+salario;
            quant_M++;

            if (salario>=5000){
                mulher_mais5000++;
            }

        }

        if(salario>maior){
            maior=salario;
        }

        if(salario<maior){
            menor=salario;
        }
    }

    printf("Salario acima de R$ 1000,00 e: %d",quant_mais1000);

    system("pause");
    return 0;

}

But the program does not stop when it reaches 20 which is the number of employees. Someone can help me?

1 answer

0


 if(i=1){
        maior=salario;
        menor=salario;
    }

When you put in a condition i = 1, every time your code gets to it, it will assign the value 1 in i, ie your for never Aira of the 1, the correct would be if (i == 1)

And by your program you should erase that, because it doesn’t make sense, you’ve already put down the conditions that define the lowest and highest wage.

  • Oops, it’s true! I forgot about that detail, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.