Unexpected value is being displayed

Asked

Viewed 768 times

2

  1. Do 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 you receive, following the rules below:

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

b. Overtime is worth ¼ of minimum wage;

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

d. The amount receivable for overtime equals the number of overtime worked multiplied by the value of overtime;

e. The salary to be received is equivalent to the gross wage plus the amount to be received 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);
  • 1

    Your first problem posted here has been solved? What is the problem of this now?

  • The first was solved yes.

  • This error is in processing, the final salary is showing 0

  • 1

    Always try to post as much information as possible to help people understand their problem. Then take a look at this: [tour]. I’ve found the problem with this one.

  • 1

    Did you try to print the individual values read? And the intermediate values? This can help you better identify where the bug is instead of looking at the program as a whole and wondering where it might be.

  • Okay, thank you! I’m sorry, I’m new around here so I’m still learning. Thank you so much for the strength!

  • @Karolaynesantos it is normal to take a while to get the hang of it, we are here to help. Do not forget to read the [tour]

Show 2 more comments

1 answer

5

The problem is the tag of formatting the scanf(). To read a type value double the 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);
}

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.


To learn more about formatting specifications:

Format string Specifications

Browser other questions tagged

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