Unexpected value is being displayed

2
  
  • Make a program that receives the number of hours worked, the value of the minimum wage and the number of overtime worked, calculate and show the salary to be received, following the rules below:
  •   

    a. The hour worked is 1/8 of the minimum wage;

         

    b. Overtime is worth ¼ of the minimum wage;

         

    c. The gross wage equals the number of hours worked multiplied by the value of the hour worked;

         

    d. The amount to be paid for overtime equals the number of overtime worked multiplied by the overtime value;

         

    e. The salary to be received is equal to the gross salary plus the amount to be paid for overtime.

    Code

    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[]) {
        //Variáveis
        double numero_horas_trabalhadas;
        double salarioMinimo;
        double numero_horas_extras;
        double valor_hora, valor_hora_extra, salarioBruto, salarioTotal;
        //Entrada de dados
        printf("Olá, vamos calcular o seu salário!");
        printf("\nDigite as horas trabalhadas: ");
        scanf("%f",&numero_horas_trabalhadas);
        printf("\nDigite o valor do salario minimo: ");
        scanf("%f",&salarioMinimo);
        printf("\nDigite o numero de horas extras trabalhadas: ");
        scanf("%f",&numero_horas_extras);
    
        //Processamento
        valor_hora = salarioMinimo/8;
        valor_hora_extra = salarioMinimo/4;
        salarioBruto = (numero_horas_trabalhadas * valor_hora);
        valor_hora_extra = (numero_horas_trabalhadas * valor_hora_extra);
        salarioTotal = salarioBruto + valor_hora_extra;
        //Saída de informação
    
    printf ("O valor do salario minimo e : %f",salarioTotal);
    
        
    asked by anonymous 11.04.2015 / 02:42

    1 answer

    5

    The problem is the tag formatting scanf() . To read a value of type double correct is %lf and not just %f :

    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char *argv[]) {
        //Variáveis
        double numero_horas_trabalhadas;
        double salarioMinimo;
        double numero_horas_extras;
        double valor_hora, valor_hora_extra, salarioBruto, salarioTotal;
        //Entrada de dados
        printf("Olá, vamos calcular o seu salário!");
        printf("\nDigite as horas trabalhadas: ");
        scanf("%lf",&numero_horas_trabalhadas);
        printf("\nDigite o valor do salario minimo: ");
        scanf("%lf",&salarioMinimo);
        printf("\nDigite o numero de horas extras trabalhadas: ");
        scanf("%lf",&numero_horas_extras);
        //Processamento
        valor_hora = salarioMinimo/8;
        valor_hora_extra = salarioMinimo/4;
        salarioBruto = (numero_horas_trabalhadas * valor_hora);
        valor_hora_extra = (numero_horas_trabalhadas * valor_hora_extra);
        salarioTotal = salarioBruto + valor_hora_extra;
        //Saída de informação
        printf ("O valor do salario minimo e : %f",salarioTotal);
        return 0;
    }
    

    See working on ideone .

    To learn more about formatting specifications:

    Format string specifications

        
    11.04.2015 / 02:56