Hey Salem!
Thanks for the tip, definitely a brainfart on my end with regards to the recursion implementation.
Code:
#include <stdio.h>#include <stdlib.h>
float s_exp(float sub_exp, char op);
char get_op();
float get_num();
int main()
{
float exp;
char op;
printf("Please enter an arithmetic expression: ");
exp = get_num();
op = get_op();
printf("Result: %.2f", s_exp(exp, op));
return 0;
}
float s_exp(float sub_exp, char op)
{
if(op != '\n')
{
switch(op)
{
case '+':
sub_exp = sub_exp + get_num();
break;
case '-':
sub_exp = sub_exp - get_num();
break;
case ' ':
break;
default:
printf("Sorry, there was an invalid operator in your equation. Please only use +/- when using this program in the future.");
exit(0);
}
op = get_op();
sub_exp = s_exp(sub_exp, op);
}
return sub_exp;
}
char get_op()
{
char next_op;
next_op = getchar();
return next_op;
}
float get_num()
{
float next_num;
scanf("%f", &next_num);
return next_num;
}
Here's where my program currently sits. Have to run some test cases, but it seems to be functioning! Thanks <3