【发布时间】:2015-10-22 21:21:34
【问题描述】:
我正在做一个计算器,用户可以输入 ,=,&&,||, ==,!即 (2>3) 或 (2>3)&&(5=”之类的表达式。唯一有效的操作是“”。 这是检查输入是否匹配操作的函数
void evalute_stack_tops(std::stack<double>& numbers, std::stack<char>& operations){
double operand1,operand2;
operand2= numbers.top();
numbers.pop();
operand1= numbers.top();
numbers.pop();
if(operations.top()=='<')
{
numbers.push(operand1<operand2);
}
else if (operations.top()=='>')
{
numbers.push(operand1>operand2);
}
else if(operations.top()=='>='){
numbers.push(operand1 >= operand2);
}
}
【问题讨论】:
-
您的堆栈是单个字符,这就是为什么只有单个字符值比较有效。尝试制作一堆
std::strings(或char *)。
标签: c++ stack boolean calculator