Calculator revisited calcc Write a four function calculator
Calculator revisited (calc.c) Write a four function calculator (+,-,*,/) that works with an arbitrary number of inputs. This means that instead of just taking two inputs it takes numbers and operations until the user decides to quit (the program runs in an infinite loop). Give updates on the current total after each operation and allow the user the choice to continue or choose a new operation each time. Total starts at 0.0 and the menu choice 5 is used to signal end of computation. Place the add, subtract, multiply, and divide functionality inside independent functions.
Implement these functions:
double add(double sum, double value);
double subtract(double sum, double value);
double multiply(double sum, double value);
double divide(double sum, double value);
THE OUTPUT SHOULD BE SOMETHING LIKE THIS:
Language in C
1 add 2: subtract 3: multiply 4 divide 5: quit enter number to add: Total is: 5.000000 1 add 2: subtract 3: multiply 4 divide 5: quit enter number to multiply Total is 25.000000 1 add 2: subtract 3: multiply 4 divide 5: quit enter number to divide can not divide by 0, ignoring value and continuing Total is 25.000000 1 add 2: subtract 3: multiply 4 divide 5: quit Final total is: 25.000000Solution
In your problem data type is given double but i tried with int it is working..
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
int sum;
int value;
void add(int ,int);
void sub(int ,int);
void mul(int,int );
void divs(int ,int);
int main()
{ int n;
char ch;
while(1)
{
printf(\"\ 1.Addition \ 2.subtraction \ 3.multiplicaton \ 4.devision \ 5.exit \ \");
printf(\"enter your choice:\");
scanf(\"%d\",&n);
printf(\"enter the value:\");
scanf(\"%d\",&value);
switch(n)
{
case 1:{
add(sum,value);
break;}
case 2:sub(sum,value);
break;
case 3:mul(sum,value);
break;
case 4:divs(sum,value);
break;
case 5:exit(1);
}
}
}
void add(int sum1,int value1)
{
sum=sum+value;
printf(\"the result: %d\",sum);
}
void sub(int sum1,int value1)
{
sum=sum-value;
printf(\"the result: %d\",sum);
}
void mul(int sum1,int value1)
{
sum=sum*value;
printf(\"the result: %d\",sum);
}
void divs(int sum1,int value1)
{
if(value==0)
{
printf(\"zero not appilcable\");
}
else
{
sum=sum/value;
printf(\"the result: %d\",sum);
}
}

