1
At the beginning of the code I declare the variable nome
as char
and when I try to pick up the variable nome
down there in the code gives error, I’ve tried several ways and this way this down goes right, but sometimes when the question appears to the user " Do you want to continue ? " and he answers s (yes), sometimes jumps straight to the field "type the employee’s salary:", ie. skips the part where asks the employee’s name
int cont, tinss;
char s, resp, nome[50];
float sal, novosala, val;
cont = 1;
do
{
printf("\n digite o nome do funcionario; ");
scanf("%s",&nome);
printf("\n digite o salario do funcionario: ");
scanf("%f",&sal);
if(sal <= 500)
{
novosala = sal - ((sal / 100) * 8);
val = (sal / 100) * 8;
tinss = 8;
}
else
if(sal > 500 && sal <= 1000)
{
novosala = sal - ((sal / 100) * 10);
val = (sal / 100) * 10;
tinss = 10;
}
else
if(sal > 1000)
{
novosala = sal - ((sal / 100) * 12);
val = (sal / 100) * 12;
tinss = 12;
}
printf("\n Nome: %s \n",nome);
printf("\n Salario bruto: %f \n", sal);
printf("\n Taxa de INSS: %d% \n", tinss);
printf("\n Valor de INSS %f \n", val);
printf("\n Salario liquido: %f \n", novosala);
printf("\n deseja continuar ? \n");
resp = getch();
cont = cont + 1;
}
while(resp == 's');
Note that in your specific program,
else if(sal > 1000)
may be replaced byelse
.– Alexandre Cartaxo
Did any help you more? You need something to be improved?
– Maniero
Your code is in C, not C++. Change scanf("%s",&name); to scanf("%s", name);, because name is already the address of the initial position of the array, and also review the use of the getch function. Check that the input buffer is not getting dirty after Resp reading.
– anonimo