I need a program that adds and multiplies as the user chooses and then select the corresponding function that will read the values until the user types 0 and the program generates the result. My program for any value typed is reporting 36. And another, if I wanted to repeat the process (calculate), and give the option to exit, would I have to use one of while
? but when do 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;
}