Why can not I change a variable in C by performing an arithmetic operation with it? [closed]

0

I'm not getting the expected result:

libraries ...

int main (void){
    float c,r;
    setlocale(LC_ALL,"");
    printf("Digite o salário\n");
    scanf("%f",&c);
    printf("Digite o reajuste percentual:\n");
    scanf("%f",&r);
    r=r*0,01;
    c=(c* r)+c;
    printf("Salário reajustado: %.2f\n",c);
    return 0;
    }

The result always comes out with the first reading of the variable c , which would be the starting salary, how do I make it "updated" in the operation just below without having to add more variables?

The following works:

libraries ...

int main (void){
    float c,r,n;
    setlocale(LC_ALL,"");
    printf("Digite o salário\n");
    scanf("%f",&c);
    printf("Digite o percentual de reajuste:\n");
    scanf("%f",&r);
    n=c+r*c;
    printf("Salário reajustado: %.2f\n",n);
    return 0;
    }

But in addition to the additional variable, the user would have to add the real-world reset from 0 to 1, not to mention that I'm sure I'll need to use that in the future. How can I troubleshoot?

    
asked by anonymous 03.04.2017 / 03:43

1 answer

1

Do not use commas for decimal places, use period.

#include <stdio.h>

int main (void){
    float c, r;
    printf("Digite o salário\n");
    scanf("%f", &c);
    printf("Digite o reajuste percentual:\n");
    scanf("%f", &r);
    r *= 0.01;
    c = c * r + c;
    printf("Salário reajustado: %.2f\n", c);
}

See running on ideone . And at Coding Ground . Also put it on GitHub for future reference .

Just be careful that this code has several other problems, do not think that just because it is working that is right.

    
03.04.2017 / 03:53