Postfix evaluate questions

Need help with my function. Heres the question:
you should write a function evaluate() that performs the task of evaluating a postfix expression. The function should read in the operands by calling a function input() described below. After the operands have been read, the operators will be read one at a time. Now, for each operator read, the function should pop two elements from the stack operands, perform the specified operation on the two operands and push the result back onto the stack operands. this should be repeated untill there is only one element on the stack operands. You should define a function input() that reads in the postfix expression one element at a time. To simplify things the operands should be input first and pushed onto the stack operands.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream>
#include<stack>
using namespace std;
stack <int> operands;
void evaluate(int);
void input();

void main()
{
	
	

}

void evaluate()
{
	int var;
	int var1;
	input();
	var =operands.top();
	operands.pop();
	var1 =operands.top();
	operands.pop();

	switch(op)
	{
	case "+": operands.push(var+var1);
		break;
	case "-": operands.push(var-var1);
		break;
	case "*": operands.push(var*var1);
		break;
	case "/": operands.push(var/var);
		break;
	default: cout << "That is not a valid operator." <<endl;
		break;
	}







}

void input( char)
{
	int x;
	int y;
	char op;
	int count=0;
	int num;
	cout << "Please enter how many numbers you would like to postfix evaluate." <<endl;
	cin >> x;
	while(count <x)
	{
		operands.push(x);
		cout << "Please enter the numbers you would like to evaluate." <<endl;
		cin >> num;
		count++;
	}
	cout << "Please enter how many operands you would like to use." << endl;
	cin >> y;
	while (count <y)
	{
		
		operands.push(y);
		cout << "Please enter the operands you would like to use." << endl;
		cin >> op;
		count++;
	}


}
Topic archived. No new replies allowed.