1
How exactly is it made to use the switch
correctly?
Here in the code, the case
1 and 2, they function normally, but in case
3 and 4, at the time of division by 2, or by 3, to know the plots, always gives wrong the result (it seems that is divided by 22 or 23).
Or the switch
don’t do this kind of operation? I know you can do it without being a switch, but my teacher wants to.
#include <stdlib.h>
#include <stdio.h>
float valorT, valorF, Vparcelas;
int op;
main()
{
printf("Digite o valor total da sua compra: ");
scanf("%f", &valorT);
printf("Digite o numero da opcao de pagamento, estao listadas abaixo: \n");
printf("1-Dinheiro\n2-Cartao debito\n3-Cartao credito 2x\n4-Cartao credito 3x\n");
scanf("%d", &op);
if(op > 4){
printf("Opcao invalida!\n");
}
switch(op){
case 1: valorF = valorT*0.1;
printf("O valor total da sua conta ficou: %0.2f", valorT-valorF);
break;
case 2: valorF = valorT*0.2;
printf("O valor total da sua conta ficou: %0.2f", valorT-valorF);
break;
case 3: valorF = valorT*0.1;
Vparcelas = valorF/2; //ISSO DA ERRADO
printf("O valor total da sua conta ficou: %0.2f,\ne das 3 parcelas: %0.2f\n", valorT+valorF, Vparcelas);
break;
case 4: valorF = valorT*0.15;
Vparcelas = valorF/3; //ISSO TAMBEM
printf("O valor total da sua conta ficou: %0.2f,\ne das 3 parcelas: %0.2f\n", valorT+valorF, Vparcelas);
break;
}
return 0;
}
ah, I get it! but I would know how to explain to me because at the time of dividing by 2 or 3 in the code I was dividing by 22 and 23 respectively.. at least by what I tested, pq if I put 1260,23 the result of the 2 plots of 63,01
– Luciano Balestrin Correa
The calculation is all wrong. The formulas are not these, I don’t know where you got it from, so it’s not even worth looking for reasons why.
– Maniero