-2

I've started to study C this week, I'm totally new in programming in C, and when I tryed to do this exercise this error in the console keep showing up.

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

float calc(float *sall, float *salb)
{
    float hraula, insspc;
    int naula;
    printf("Digite o valor da hora-aula e o numero de aulas dadas:");
    scanf("%f%i", hraula, naula);
    printf("Digite a porcentagem do inss retirada do salário:");
    scanf("%f",insspc);
    *salb = hraula * naula;
    *sall = *salb * ((100 - insspc) / 100);
    return 0;
}

int main()
{
    float salbt, sallq;
    calc(&sallq, &salbt);
    printf("O salário bruto é: %f R$, liquido: %f R$", salbt, sallq);
    return 0;
}

Well hope someone can help me, thanks!

Azodiaks
  • 17
  • 3

2 Answers2

3
scanf(" %f%i", hraula, naula);
scanf(" %f",insspc);

It should be as scanf requires the pointers to variables:

scanf(" %f%i", &hraula, &naula);
scanf(" %f",&insspc);
0___________
  • 60,014
  • 4
  • 34
  • 74
0

Pass a pointer to the receiving variables like this:

scanf("%f%i", &hraula, &naula);

Similarly

scanf("%f", &insspc);

Reference: man 3 scanf

It is also good practice to check the return value of scanf to ensure that you have collected the correct number of values. Something like this:

if (scanf("%f%i", &hraula, &naula) != 2) {
    fprintf(stderr, "Failed to read hraula and naula\n");
    return -1;
}

and then check the return value of calc():

if (calc(&sallq, &salbt) == 0)
    printf("O salário bruto é: %f R$, liquido: %f R$", salbt, sallq);
mhawke
  • 84,695
  • 9
  • 117
  • 138