Can anyone help me with this?

Asked

Viewed 608 times

1

5) Make a program that receives the basic salary of an employee, calculate and show your salary to receive, knowing that the employee has bonus of R $ 50 and pays tax 10%

#include <stdio.h>
int main()

{
float sal,imposto,s_final;
printf(" CALCULO DE SALARIO \n \n");

printf("Digite seu salario: ");
scanf("%f",&sal);

imposto= sal/100 * 0.1;
s_final = sal-imposto+50;

printf("Salario a receber: %f reais \n",&s_final);
printf("Valor dos impostos: %f reais",&sal);
return 0;
}

inserir a descrição da imagem aqui

  • 1

    My C’s pretty rusty but I think the last two printf() no need to use &. P.S.: If the only help you want is to get the variables printed correctly, edit the question and make this clarification, otherwise the way it is can be considered not clear enough ("someone help me with this").

2 answers

1

Hello was viewing your code and the logic is correct, however, you forgot that the "&" is only used for scanf and not for printf (if you use for print will take the address of the memory and not the content).

I’ve reworked the code:

 #include <stdio.h>
 int main()
 {
 float sal,imposto,s_final;
 printf(" CALCULO DE SALARIO \n \n");
 printf("Digite seu salario: ");
 scanf("%f",&sal);

 imposto= (sal*10)/100;
 s_final = sal-imposto+50;

 printf("Salario a receber: %f reais \n",s_final);
 printf("Valor dos impostos: %f reais",sal);

 } 

I hope you helped him!

  • 1

    Thanks a lot, I’m starting now the matter of algorithms in facul is still I’m half lost kk vlw msm

0


& (and commercial) is used to pass the address of a variable, i.e., when you do : printf("Salary receivable: %f real n",&s_final); printf("Value of taxes: %f real",&salt);

the printf function is waiting for a float, because in the string it has "%f", but "&s_final" represents the address that the value of the variable "s_final" is stored.

To fix this, simply remove & in calls from printf function.

Browser other questions tagged

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