I'm supposed to make a program using getchar() to input the operation entered, then return the result of the operation after extracting the operands and the operator and calculating the result.
if you enter 15 + 30
the result should be 45
or 15+30=45
Also using user-defined functions to do the calculations for each of the different operands used (+, -. *, /, %)
I was thinking of using functions like isdigit() or ispunct() to extract the operands and operator
How should I go about doing that?
Here's what I have so far.
#include<stdio.h>
#include<ctype.h>
int add (int a, int b);
int subtract (int a, int b);
int multiply (int a, int b);
double divide (int a, int b);
int mod (int a, int b);
int main(void)
{
printf("Enter expression to calculate.\n");
getchar();
}
int add (int a, int b)
{
int c;
c=a+b;
return c;
}
int subtract (int a, int b)
{
int c;
c=a-b;
return c;
}
int multiply (int a, int b)
{
int c;
c=a*b;
return c;
}
double divide (int a, int b)
{
double c;
c=(1.0*a)/b;
return c;
}
int mod (int a, int b)
{
int c;
c=a%b;
return c;
}