Doubt in LANGUAGE C

Asked

Viewed 355 times

-4

You guys, good night. I am learning C in college and we have been asked an exercise to read the salary of an employee.(until I ask for forgiveness because close to the most experienced, my code must be garbage, but tamo ai né...) (The owner of this company determined a wage increase of 7,5% to all its employees. In addition, granted an allowance of R $ 150,00 for those who receive until and, including R $ 1750,00. Given the value of the net salary of an employee, inform the employee’s final salary.) I got mount the code in devC++ BUT it’s not reading IF and ELSE. Someone can help me ?

#include <stdio.h>
#include <stdlib.h>

int main() 
{
    int ra;
    char nome[50], empresa[40];
    float sal_hoje, sal_total, sal_reajuste;
    printf("Ola, seja bem vindo a Boxbacon \n");
    printf("Digite o seu nome completo : \n");
    scanf("%s",&nome);
    printf("Digite o seu RA : \n " );
    scanf("%d", &ra);
    printf("Digite o seu salario : \n ");
    scanf("%f", &sal_hoje);
        if(sal_hoje <= 1750)
            {
                sal_reajuste=sal_hoje * (0,075);
                sal_hoje= sal_hoje + 150 + sal_reajuste;
                sal_total=sal_hoje;
                printf("tera um salario total de : , "sal_total);
            }
        else 
            {
                sal_reajuste=sal_hoje * (0,075);
                sal_total=sal_reajuste + sal_hoje;
                printf("tera um salario total de : " sal_total);
            }
    
    return(0);

}

What appears is just that inserir a descrição da imagem aqui

Like, it doesn’t return the corrected salary in either case and I’d like to understand what’s wrong.

2 answers

0

First you do not need to ask the user to enter the company name, nor does the R.A and the full name.

First: You will create a fictitious name, the R.A has to be yours and the full name too.

Second: I see no need to use #include <stdlib.h> but, use #include <locale.h> setlocale (LC_ALL, "Portuguese"); for accents if you prefer.

The variables of float are correct. I believe you should create more suggestive names for them if you prefer. However, there is no need to have.

Following what you have already done I followed an idea for resolution.

#include <stdio.h>
#include <locale.h>
int main(){
setlocale (LC_ALL, "Portuguese");
float sal_hoje, sal_total, sal_reajuste;

printf("\nDigite o seu salario : \n ");
    scanf("%f", &sal_hoje);

        if(sal_hoje <= 1750)
            {
                sal_reajuste=sal_hoje * (0.075);
                sal_total= sal_hoje + 150 + sal_reajuste;               
             
            }
        else
            {
                sal_reajuste=sal_hoje * (0.075);
                sal_total=sal_reajuste + sal_hoje;
                
            } //obs: Nessa parte voce vai colocar a impressão das informações: sal_hoje,sal_total, sal_reajuste.

  printf(" \nO salario liquido é %2.f",sal_hoje );
obs: Os demais printf segui a mesma sequencia.
}

0

Your code if you were not reading the If and Elses, would not print the

  • shall have a total salary of :

So, the code error is in this same sentence, you did not put %f to the float print, but declared the variable. And another mistake in your code is to not put a comma after the sentence in the printf, the correct one would be:

 printf("tera um salario total de: %f",sal_total);

And another "mistake", would be the use of the comma instead of the point, in the 0.075

Code fully corrected:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int ra;
    char nome[50], empresa[40];
    float sal_hoje, sal_total, sal_reajuste;
    printf("Ola, seja bem vindo a Boxbacon \n");
    printf("Digite o seu nome completo : \n");
    scanf("%s",&nome);
    printf("Digite o seu RA : \n " );
    scanf("%d", &ra);
    printf("Digite o seu salario : \n ");
    scanf("%f", &sal_hoje);
        if(sal_hoje <= 1750)
            {
                sal_reajuste=sal_hoje * (0.075);
                sal_hoje= sal_hoje + 150 + sal_reajuste;
                sal_total=sal_hoje;
               printf("tera um salario total de: %f",sal_total);
            }
        else
            {
                sal_reajuste=sal_hoje * (0.075);
                sal_total=sal_reajuste + sal_hoje;
                printf("tera um salario total de: %f",sal_total);
            }

    return(0);
}
  • Hmmm, there’s that too. I fixed it here, but testing it again for in the same place. It doesn’t read the total wage

  • In fact there was one more error, I fixed and sent the complete code

Browser other questions tagged

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