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, is displaying 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;
}
}
In the first case is missing a ")"
– Prostetnic Vogon Jeltz
I fixed it, but it keeps showing 100 in all options. I can’t perform the operation of reducing or increasing the price in the printf function
– Carlos
You are doing whole arithmetic. Try dividing by
100.0
rather than divided by100
– Jefferson Quesado
It worked. Thank you very much, but why does it work only I put decimal number in the division?
– Carlos
@Carlos later I answer. Don’t let me forget. I’m busy right now, but I have some answers about floating dots, so maybe this will open your mind. And, yes, it is very confusing for those who are starting, do not be scared. With time gets used
– Jefferson Quesado