[COLOR=red]OK you have a few issues with your code that I'm going to point out. If you would like ideas of how to fix it just ask and I'll help you there. However I do challenge you to think about it yourself before you look for help.
[COLOR=blue]
Code:
#include <iostream.h>
int eval(char A[], int n)
{
if(n == 1)
return (int (A[0])- int('0'));
if(A[n-2] == '+')
return eval(A,n-2) + (int (A[n-1]) - int('0'));
else
return eval(A, n-2)- (int (A[n-1]) - int('0'));
}
[COLOR=red]First off I checked your input and found out that you are completely screwed if the user's input is anything but single digit numbers. That needs to be taken of. After that you are right in saying that a couple extra else if statements.
[COLOR=blue]
Code:
void main()
{
char A[20];
int n=0;
cout << "Enter a String: ";
int i=0;
A[0]=cin.get();
while(A[i] != '\n')
{
i++;
A[i]=cin.get();
}
n=i;
for(i =0; i < n; i++)
cout << A[i];
cout << endl;
cout << eval(A,n) << endl;
}
[COLOR=red]Secondly you need to do some crash guarding and put in a line of code to make sure the user didn't just hit enter when prompted to use the calc.