Em dùng thư viện stack để làm phép toán hậu tố, nhưng khi sử dụng pop thì nó bị lỗi là
error: void value not ignored as it ought to be
val1 = s.pop();
^
…
Các anh chị xem và chỉ giúp em với, em cảm ơn ạ.
#include <iostream>
using namespace std;
#include <iostream>
#include <fstream>
#include <stack>
using namespace std;
#define MAXCHAR 100
int CalculatePostfix(char postfix[])
{
stack<int> s;
for (int i = 0; postfix[i]; ++i)
{
if (isdigit(postfix[i]))
s.push(postfix[i] - '0');
else
{
int val1 = s.pop();
int val2 = s.pop();
switch (postfix[i])
{
case '+': s.push(val2 + val1); break;
case '-': s.push(val2 - val1); break;
case '*': s.push(val2 * val1); break;
case '/': s.push(val2/val1) ; break;
}
}
}
return s.pop();
}
int main() {
// your code goes here
return 0;
}

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?