I am trying to write a calculator that calculates most mathematical operations in Reverse Polish Notation. However, i know im doing it right but when i try compiling it with just cc advcalc.c it gives me these errors... advcalc.c: In function ‘main’:
Code:
advcalc.c:31: error: invalid use of void expression
advcalc.c:33: error: invalid use of void expression
advcalc.c:35: error: invalid use of void expression
advcalc.c:37: error: invalid use of void expression
advcalc.c:38: warning: comparison between pointer and integer
advcalc.c:39: error: invalid use of void expression
advcalc.c:40: warning: comparison between pointer and integer
advcalc.c:41: error: invalid use of void expression
advcalc.c:42: warning: comparison between pointer and integer
advcalc.c:43: error: invalid use of void expression
advcalc.c:44: warning: comparison between pointer and integer
advcalc.c:45: error: invalid use of void expression
advcalc.c:46: warning: comparison between pointer and integer
advcalc.c:47: error: invalid use of void expression
advcalc.c:48: warning: comparison between pointer and integer
advcalc.c:49: error: invalid use of void expression
advcalc.c:50: warning: comparison between pointer and integer
advcalc.c:51: error: invalid use of void expression
advcalc.c:52: warning: comparison between pointer and integer
advcalc.c:53: error: invalid use of void expression
advcalc.c:57: error: expected declaration or statement at end of input
any input?
Code:
//RPN postfix calculator
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
//53* 4 7 8 9 * + cos * + (5*3+4*cos(7+8*9)-original numerator
//9 3 * 2 sqrt (9*3-sqrt(2))
double stack[1000];
int tos= -1;
void push(double v){
if (tos>999){printf ("Stack Overflow\n");exit(0);}
tos++;
stack[++tos]=v;
}
double pop(){
double v;
if(tos < 0){printf("stack underflow\n");exit(0);}
v=stack[tos--];
//v=stack[tos--];
return v;
}
int main(int argc,char **argv){
int x,y,z;
char q;
q=argv[1][0];
if ((q=='-')|| (('0'<=q)&&(q<='9'))){
tos = getchar();
if (tos == '+')
{printf("The sum is: %f\n",push(pop() + pop())); }
if (tos == '-')
{printf("the result is: %f\n", push(pop() - pop())); }
if (tos == 'x')
{ printf("the result is: %f\n", push(pop() * pop()));}
if (tos == '/')
{ printf("the result is: %f\n", push(pop() / pop()));}
if (tos == "sqrt")
{printf("the result is: %f\n", push(sqrt((double)pop())));}
if (tos == "qbrt")
{ printf("the result is: %f\n", push(qbrt((double)pop())));}
if (tos == "sin")
{ printf("the result is: %f\n", push(sin((double)pop()))); }
if (tos == "cos")
{ printf("the result is: %f\n", push(cos((double)pop()))); }
if (tos == "tan")
{printf("the result is: %f\n", push(tan((double)pop())));}
if (tos == "asin")
{ printf("the result is: %f\n", push(asin((double)pop())));}
if (tos == "acos")
{ printf("the result is: %f\n", push(acos((double)pop()))); }
if (tos == "atan")
{printf("the result is: %f\n", push(atan((double)pop())));}
}
else{ printf("Please enter a valid integer first\n");
exit(0);
}