i've been working on this for 2 days now and i can't seem to get it done. my brain's really drained and i've to submit this in 1 and a half hour that's why i decided to seek help.

the calculator should be able to calculate the following: 4 basic operations, power (^), factorial (!), sin (s), cos (c), and nth root of a number (r).

examples of what the user can enter are: (those in bold are user inputs)

5+5

10^2

100-50

50r2

7.0710 and so on

it can also be

5!

120-115

5s

0.087 and so on

but all i've accomplished after 2 days is only 1 operation! say 5+5 or 68^2 and so on.. there's no continuity in the calculator.

i can't seem to figure out the scanf for 3 inputs (say5^2in first calculation), 2 inputs (say5+5in either initial or succeeding calculation) or 1 input (say 5!in succeeding calculation).

i know the codes for the 9-functions and ran them individually, but i can't seem to put them together!

i hope someone would help me on this. thanks.

Code:#include <stdio.h> double sum(double x,double y); double diff(double x,double y); double prod(double x,double y); double quo(double x,double y); double power(double b,double e); double factorial(double x); double sine(double x); double cosine(double x); double root(double base,double rad); int main(){ double a,b,result; char o; printf("Legend\n + - * / ^ ! s c r\n"); for(;1;){ scanf("%lf%c%lf",&a,&o,&b); getchar(); switch(o) { case '+': result=sum(a,b); printf("%.2lf",result); break; case '-': result=diff(a,b); printf("%.2lf",result); break; case '*': result=prod(a,b); printf("%.2lf",result); break; case '/': result=quo(a,b); printf("%.2lf",result); break; case '^': result=power(a,b); printf("%lf",result); break; case '!': result=factorial(a); printf("%.0lf",result); break; case 's': result=sine(a); printf("%.4lf",result); break; case 'c': result=cosine(a); printf("%.4lf",result); break; case 'r': result=root(a,b); printf("%.6lf",result); break; default: main(); } } scanf("%c%lf",&o,&a); switch(o){ case '+': result=sum(result,a); printf("%.2lf",result); break; case '-': result=diff(result,a); printf("%.2lf",result); break; case '*': result=prod(result,a); printf("%.2lf",result); break; case '/': result=quo(result,a); printf("%.2lf",result); break; case '^': result=power(result,a); printf("%lf",result); break; case '!': result=factorial(result); printf("%.0lf",result); break; case 's': result=sine(result); printf("%.4lf",result); break; case 'c': result=cosine(result); printf("%.4lf",result); break; case 'r': result=root(result,a); printf("%.6lf",result); break; default: main(); } getchar(); getchar(); } double sum(double x, double y){ double sum; sum=x+y; return sum; } double diff(double x, double y){ double diff; diff=x-y; return diff; } double prod(double x, double y){ double prod; prod=x*y; return prod; } double quo(double x,double y){ double quo; quo=x/y; return quo; } double power(double b,double e){ if(b==0 && e==0){ printf("Invalid.\n"); main(); } else if(e==1){ return b; } else if(e==0){ return 1; } else{ return b*power(b,e-1); } } double factorial(double x){ int ctr; double fact; if(fact<0){ printf("Invalid.\n"); main(); } else{ fact=1; for(ctr=1;ctr<=x;ctr++){ fact*=ctr; } return fact; } } double sine(double x){ int n; double sin,final_sin=0; for(n=0;n<=200;n++){ sin=(power(-1,n)*power(x,(2*n)+1))/factorial((2*n)+1); final_sin+=sin; } return final_sin; } double cosine(double x){ int n; double cos,final_cos=0; for(n=0;n<=200;n++){ cos=(power(-1,n)*power(x,2*n))/factorial(2*n); final_cos+=cos; } return final_cos; } double root(double base, double rad){ double up,low,fu,fl,m,fm; printf("\nEnter radicand: "); scanf("%lf",&rad); printf("\nyour equation is x^(%lf) - %lf = 0.",rad,base); printf("\nEnter upper limit: "); scanf("%lf",&up); printf("enter lower limit: "); scanf("%lf",&low); fu=power(up,rad)-base; fl=power(low,rad)-base; printf("\nfu=%lf and fl=%lf.",fu,fl); if((fu*fl)<0){ while((up-low)>0.00001) { m=(up+low)/2; fm=power(m,rad)-base; if((fu*fm)>0){ up=m; } if((fu*fm)<0){ low=m; } } } else{ printf("\nInvalid guesses.\n"); power(base,rad); } return m; }