0
I need to do a program that calculates the average salary of a company, asking the user for the amount of employees, the name and salary of each employee and returning the average, the name of the employee with the highest salary and the name of the employee with the lowest salary.
The program must first request the number of employees and then ask for the names of each one of them.
The program is almost ready, the only problem is that at the time of execution it does not show the names as it should show, but rather a lot of meaningless characters. Can someone tell me where my mistake is?
char nome[11], nome_maior[11], nome_menor[11];
int quant, cont = 1;
float salario, salario_maior = 0, salario_menor=999999, media, soma;
printf("Digite a quantidade de funcionários: "); scanf("%d", &quant);
while(cont <= quant){
printf("\nInsira o NOME do funcionário: "); scanf("%s", nome);
printf("\nInsira o salário: "); scanf("%f", &salario);
soma = soma + salario;
cont = cont + 1;
if(salario < salario_menor){
nome_menor == nome;
salario_menor = salario;
}if(salario > salario_maior){
nome_maior == nome;
salario_maior = salario;
}}
printf("\nO maior salário é de %s com %.2f", nome_maior, salario_maior);
printf("\nO menor salário é de %s com %.2f", nome_menor, salario_menor);
printf("\nA média dos salários apresentados é de %.2f", media=salario/quant);
return 0;
if(salario < salario_menor){ nome_menor == nome;
This does not do what you want for several reasons. First of all it is==
of comparison and not=
assignment and second string assignment in C is done withstrcpy
. Related or duplicate Copy Strings in C, What is the difference between assigning and comparing string variables with function or with assignment and comparison operator?– Isac
I still entered the contents of strcpy, the most we saw about string was the basics of the basic, we didn’t even enter the string library, but if the question asks this I’ll look into how to use it. Thank you!
– Helender