Program in C compiles but shows error in Output

Asked

Viewed 63 times

-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

Can anyone tell me why when compiling in Xcode this code in C it presents the message below? PS In other compilers the message is not shown...

Program ended with Exit code: 01000

Thank you!

  • Well, in previous versions, if you try to output Target on the console, it will remove the line from the output code. However, in newer versions of Xcode, you get stuck with it if you create a command line project. The code contains no errors.

  • 1

    Hello @redronew. Avoid placing images of your code, instead edit your question and put there the formatted code.

  • 2

    How much you put in salary ? 1000 ? It seems to me that the text has been overlaid, and that the exit code is 0 and stuck to the 1000 incoming, giving 01000. That is "Program ended with Exit code: 0" and then the "1000"

  • 1

    In the scanf function we must provide the address of the variable that will receive the value: scanf("%f", &sal); scanf("%f", &per);

  • Isac... Really, after the compilation the message "Program ended with Exit code: 01000" is superimposed exactly where I enter the input data in the console......

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 entered value

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;
}

Browser other questions tagged

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