making more progress. Eliminated all compiler errors but 1:
Code
proj2.cpp: In function `int pop()':
proj2.cpp:63: error: 'struct stack' has no member named 'val'
offending area:
Code
int pop()
{
[b]int item = calcStack->val;[/b]
stack *tempPtr = calcStack;
calcStack = calcStack->next;
delete tempPtr;
return item;
}
declarations:
Code
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
struct stack
{
int value;
stack *next;
};
stack *calcStack = NULL;
void push(int num);
int pop();
bool isEmpty();
void operation(char op);
void operation2(char op);
Not sure why it won't work? Obviously it doesn't point to anything because nothing has been pushed yet. How do you get pop to behave when there is nothing there yet?
Quote (Richter @ Sep 29 2012 04:27pm)
I guess you also want to deal with integers which are longer than just 1 digit? so taking 1 digit of an integer (which is as example 3 digits long) and converting each of those 'char' of the string to an integer is kind of... pointless...
you need a strategy... tell us possible inputs:
example:
1) 3 2 +
2) 13 5 -
3) 83 3 /
4) 54.3 4.2 *
5) 4
6) 2
7) /
8) 12.2
9) 4 1
I guess there are only integers, so number 8 and number 4 are not possible?
I guess that there is always a whitespace between the integers and the operators?
I guess that integers may be longer than 1 digit?
I guess that the program should do something after each 'newline'?
Here is an example input (professor wrote it)
Code
2 4 * 3 - p
5 2 4 + * p
5 u 4 - 3 / p
5 4 - u 2 * p
7 u 12 - u 3 4 - * 7 / p e
er.....crap. Now I have to deal with 2 digit ints? damn....
edit: let me sum up my strategy I guess:
I need to read in a line of inputs. They can be +, -. *. /, p, e , u or an integer
if its an integer, push it on the stack. If its an operator, perform the selected operator.
What I wanted to do was read a line of input up until a newline char was found.
Put that input into a string (I guess...)
check each element to see what it contains. If it contains an integer, use atoi (thought it would be easy, wasn't) and push it on the stack.
If it contains something else, check to see whether it was a mathematical op or if it was something else. Then perform those selected ops.
It would loop through user inputs until the end of file was reached.
This post was edited by Eep on Sep 29 2012 03:35pm