1
I am making a calculator. The program performs operations depending on the number the user chooses.
The problem is that when you type 5 it is to end the loop and this is not happening.
int main(void){
float x,y;
int operador;
do{
printf("\n\nEscolha a operacao:");
printf("\n\t1-SOMA\n\t2-SUBTRACAO\n\t3-MULTIPLICACAO\n\t4-DIVISAO\n\t5-SAIR\n");
scanf("%d",&operador);
printf("Primeiro numero:");
scanf("%f",&x);
printf("Segundo numero:");
scanf("%f",&y);
switch(operador){
case 1:
printf("RESULTADO:%0.2f",x+y);
break;
case 2:
printf("RESULTADO:%0.2f",x-y);
break;
case 3:
printf("RESULTADO:%0.2f",x*y);
break;
case 4:
printf("RESULTADO:%0.2f",x/y);
break;
}
}while(operador!=5);
printf("...Voce encerrou a calculadora...");
}
Here finished. In insert the value 5, he asked for the values of the first and second numbers, as expected and then finished the loop of repetition. What happens when you put the 5?
– Woss
He starts again, asks to indicate the operation and the two numbers
– user133918
Does it start again or just continue the execution as it should? For after you read the value of
operador
you will always read the value ofx
andy
, regardless of the value ofoperador
. If you type 5 tooperador
and any values forx
andy
the program will end as expected. This is not the behavior you wanted?– Woss
Here for me, when I type 5 for operator and any value for x e y, it does not end. He was supposed to show the last printf of the code and finish, it doesn’t happen
– user133918