C program compiles but output error

-1
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

float bonus_a_receber(float salario, float perc){
    float a_pagar;
    a_pagar = (salario * perc) / 100;
    return a_pagar;
}

int main(int argc, const char * argv[]){
    setlocate(LC_ALL, "portuguese");
    float sal, per, total;
    printf("Digite o seu salário: ");
    scanf("%f", $sal);
    printf("Digite o percentual do bonus: ")
    scanf("%f", per);
    total = bonus_a_receber(sal, per);
    printf("Bonus a receber R$ %.2f\n", total);

    return 0;
}

Output

Digite o seu salário: Program ended with exit code: 01000
Digite o percentual do bonus: 10
Bonus a receber R$ 100.00

Does anyone know how to tell me why compiling in Xcode this code in C does it display the message below? PS In other compilers the message is not displayed ...

  

Program ended with exit code: 01000

Thank you!

    
asked by anonymous 25.09.2018 / 07:31

1 answer

0

There were some errors in the code: 1 - first, the correct is "setlocale" not "setlocate" 2 - after scanf it is necessary to put "&" for the variables that will receive the value typed

Follow the corrected code:

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

float bonus_a_receber(float salario, float perc){
   float a_pagar;
   a_pagar = (salario * perc) / 100;
   return a_pagar;
}

int main(int argc, const char * argv[]){
   setlocale(LC_ALL, "portuguese");
   float sal, per, total;
   printf("Digite o seu salário: ");
   scanf("%f", &sal);
   printf("Digite o percentual do bonus: ");
   scanf("%f", &per);
   total = bonus_a_receber(sal, per);
   printf("Bonus a receber R$ %.2f\n", total);

   return 0;
}
    
05.10.2018 / 16:30