1
I would like the switch
show me the sum if I choose case 1
as follows the code, but it does not perform the operations.
#include<stdio.h>
int main() {
int a,b;
int operacao;
int soma = a + b;
int subtracao = a - b;
int multiplicacao = a * b;
int divisao = a / b;
//exponenciacao;
printf("digite o primeiro numero:\n");
scanf("%d", &a);
printf("digite o segundo numero:\n");
scanf("%d", &b);
printf("Qual operacao voce deseja ?\n");
printf(" 1 Soma\n 2 Subtracao\n 3 Multiplicacao\n 4 Divisao\n");
scanf("%d", &operacao);
switch(operacao)
{
case 1:
printf("voce escolheu soma %d", soma); *// AQUI EU GOSTARIA QUE ELE REALIZASSE A SOMA, PORÉM ELE SEMPRE APRESENTA O VALOR 10557854*
break;
case 2:
printf("voce escolheu Subtracao %d", subtracao);
break;
case 3:
printf("voce escolheu Multiplicacao %d", multiplicacao);
break;
case 4:
printf("voce escolheu Divisao %d", divisao);
break;
}
}
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.
– Maniero