Heres the question and expected output:
Heres the error im getting:
Heres my code:
// list of libraries
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include "STACKPAC.h"
using namespace std;
//all function prototypes
//main function
int main()
{
int value, x, y, r;
int tom, jerry, mickey;
Stack<int, 10> p;
p.clearStack();
cout << "Enter a postfix expression: ";
string id;
while (cin >> id, id != "$")
{
//chech whether the input is a number
//. If it is, then convert it to its
//numeric value
if (isdigit(id[0]))
{
value = stoi(id);
p.pushStack(value);
}
if (id == "tom")
{
cout << "Enter the value of tom: "; cin >> tom;
p.pushStack(tom);
}
else if (id == "jerry")
{
cout << "Enter the value of jerry: "; cin >> jerry;
p.pushStack(jerry);
}
else if (id == "mickey")
{
cout << "Enter the value of mickey: "; cin >> mickey;
p.pushStack(mickey);
}
else if (id == "+")
{
x = p.popStack();
y = p.popStack();
r = y + x;
p.pushStack(r);
}
else //if (id=="*")
{
x = p.popStack();
y = p.popStack();
r = y * x;
p.pushStack(r);
}
}
//pop the stck to see the result
cout << "\tValue of the expression is: " << p.popStack() << endl;
system("pause");
return 0;
}