Sure. Here's where I'm at currently.
Code:
//Header Files
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#define MAX_BUFFER_SIZE 100
#define MAX_STACK_SIZE 100
//Start of main function
int main(void)
{
//Declarations
char buff[MAX_BUFFER_SIZE];
double x, stack[MAX_STACK_SIZE];
int i, num_operand=0;
//Program Title
printf(" REVERSE POLISH CALCULATOR\n");
printf("-------------------------------------------------\n");
while(x != 'q')
{
//This reads a string from the user
if( scanf("%s", buff) < 1 )
{
printf("I did not understand \n");
return 0;
}
//Checks to see if the user entered a number
if(isdigit(buff[0]) || isdigit(buff[1]))
{
//Turns string into number and puts value in x
sscanf( buff, "%lf", &x);
//Place statements here to handle getting a number
if (num_operand < MAX_STACK_SIZE)
{
stack[num_operand]=x;
num_operand ++;
}
else
{
printf("No more space on stack \n");
}
}
else
{
//Place statements to do operations
switch(buff[0])
{
//To handle addition
case '+':
if(num_operand >= 2)
{
stack[num_operand] = stack[num_operand - 1] + stack[num_operand - 2];
num_operand --;
}
else
{
printf("Not enough operands in stack for operation \n");
}
break;
//To handle subtraction
case '-':
break;
//To handle multiplication
case '*':
break;
//To handle division
case '/':
break;
//To handle listing what's currently in the stack
case 'l':
printf("Values in the stack are: \n");
for(i = 0; i < num_operand; i++)
{
printf("--%5.3lf \n", stack[i]);
}
break;
//To handle popping a number off the stack
case 'p':
num_operand--;
break;
//To handle quitting the program
case 'q':
return 0;
break;
}
}
}
}
I think I've got the input part down, now I'm working on the mathematical side of things. I know my addition switch is wrong already cause I doesn't work when I run it . Maybe a clue on how to add numbers in array?