3
Good evening, I was testing this C code of an activity* of my course, works ok if (c<101||c>103), works ok if if (c=101), but if (c=102) if instead of returning me ns=s+(s*0.2), is returning me the previous one, ns=s+(s*0.1), the same is true if if (c=103) which should return ns=s+(s*0.3) but also returns ns=s+(s*0.1). Could you clear me of the question of what the problem is and how I should fix it? Thank you.
#include<stdio.h>
#include<stdlib.h>
main()
{
float s,c,ns;
printf ("Cod. do Cargo:");
scanf ("%f",&c);
printf ("Salario:");
scanf ("%f",&s);
if (c<101||c>103)
{
ns=s+(s*0.4);
}
else if (c=101)
{
ns=s+(s*0.1);
}
else if (c=102)
{
ns=s+(s*0.2);
}
else if (c=103)
{
ns=s+(s*0.3);
}
printf ("Salario Antigo: R$ %.2f",s);
printf ("\nNovo Salario: R$ %.2f",ns);
printf ("\nDiferenca: R$ %.2f",ns-s);
}
*
*The activity was this: A company will grant a salary increase to its employees, variable according to the position, according to the table below. Make an algorithm that reads the salary and position of a employee and calculate the new salary. If the employee’s position does not is in the table, it should then receive a 40% increase. Show the old salary, new salary and difference.
Code Position Percentage 101 Manager 10% 102 Engineer 20% 103 Technician 30%
*
Perfect, I missed the difference between = and ==, thank you very much!
– Newton Sandey
@Newtonsandey if the answer solved the problem, you can accept it as correct!
– rLinhares