2
I need a program that performs sum and multiplication according to the user’s choice and later select the corresponding function that will read the values, until the user enters 0 and the program generates the result. My program for any typed value is reporting 36. And another, if I wanted to repeat the process (calculate), and give the option to leave, would have to use one of the while
? but when I get out of the loop?
#include <stdio.h>
void soma(void){
int valor, soma, result;
soma = 0;
printf("Foi escolhida a soma:\n\n");
do{
printf("Informe os valores desejados e 0 (zero) para concluir:");
scanf("%d", &valor);
soma= soma+valor;
result=soma;
}while(valor!=0);
}
void mult(void){
int valor, mult,result;
mult= 1;
printf("Foi escolhida a multiplicacao:\n\n");
do{
printf("Informe os valores desejados e 0 (zero) para concluir:");
scanf("%d", &valor);
if(valor==0){
break;
}
mult= mult*valor;
result=mult;
}while(valor!=0);
}
int main()
{
int op,result;
printf("Informe a operacao desejada soma(1) ou produto (2):");
scanf("%d", &op);
if(op==1){
soma();
}
else if(op==2){
mult();
}
printf("O resultado foi: %d", result);
return 0;
}
The program only does two operations multiplication and sum?
– gato
Yeah just that
– RafNP