Price calculation algorithm does not display the result correctly

0

I'm trying to make an algorithm to calculate what should be paid for a product, considering the normal price tag and the choice of payment condition, but it can not calculate, it will display the value 100.

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

void main()
{
    float valor;
    int cod_pagamento;

    printf("Insira o valor do produto: R$");
    scanf("%f", &valor);

    printf("Insira a forma de pagamento: ");
    scanf("%d", &cod_pagamento);

     switch(cod_pagamento){
        case 1:
            printf("Voce vai pagar R$ %.2f", valor-((10/100)*valor));
            break;
        case 2:
            printf("Voce vai pagar R$ %.2f", valor-((5/100)*valor));
            break;
        case 3:
            printf("Voce vai pagar R$ %.2f", valor);
            break;
        case 4:
            printf("Voce vai pagar R$ %.2f", valor+((10/100)*valor));
            break;
        default:
            printf("Selecione uma das opções para realizar o pagamento");
            break;
    }   
}
    
asked by anonymous 09.02.2018 / 18:07

2 answers

-1

You can do for example (since the values are static):

case 1:
    aux = (valor - 1) * valor;
    printf ("Voce vai pagar R$ %.2f", aux );
    
09.02.2018 / 18:20
-1

You should not be running the same program that compiles.

As a commentary has been noticed, a ) is missing in the first case -

       printf("Voce vai pagar R$ %.2f", valor-((10/100)*valor));

It opens 3 parentheses, and closes only 2. This happens in all its other printf : in this condition the program does not compile. You may be changing the source code, but the program that runs is always the last one that could be compiled - in this case it should be some test that only printed "100".

Just pay attention to your compiler and environment error messages to see the syntax errors, as well as the date and time of the executable file (".exe", if it is windows) that you are running.

    
09.02.2018 / 19:01