1
I need the negative values entered by the user not enter the calculation and, still, this negative insertion is canceled by the program.
The statement reads as follows::
A city hall did a survey among its inhabitants, collecting data on people’s salaries. The city wants to know:
- The average wage of the population.
- Highest salary.
- The amount of people with salaries above R $ 1,000.00
The end of the reading of the data will happen with the entry of a negative salary.
Part of the code I’ve already made:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int quant_sal=0,salario_1000=0,soma=0,maior=0;
float salario=1;
printf("Insira o salario: ");
scanf("%f",&salario);
maior=salario;
while(salario>=1){
soma=soma+salario;
if(salario<=0){
printf("Salario invalido");
}
if(salario>1000){
salario_1000++;
}
if(salario>maior){
maior=salario;
}
printf("Insira o salario: ");
scanf("%f",&salario);
}
printf("A media de salario e: %.1f\n",soma/salario);
printf("O maior salario e: %d\n",maior);
printf("Salario acima de 1000 e: %d\n",salario_1000);
system("pause");
return 0;
}
Oops, it worked! Only in (larger=0;), when I put in float he did not do the tracking, but I left in int and it worked. Anyway, thank you for taking the time to verify the code. Ended up helping me and teaching me a few little things that I was in doubt.
– HuckBoy
@Huckboy If this answer solved your problem, mark it as accepted by clicking on the " " that is next to it. This will also mark your question as solved/solved. If you are still not satisfied and have any doubts or objections, feel free to comment.
– Victor Stafusa
rss, I forgot that detail!! Thank you!
– HuckBoy