please help me in this code
HELLO EVERY ONE
HOW ARE YOU?
i want you to help me please
i have question and i am try to solve it
but when put my code in compiler is not work
i really need help
the question is
Write a program that reads a string of arithmetic expression from the keyboard, and evaluates the arithmetic operation in the string. Your program should accept only
• Positive Real or Integer Numbers
• The four basic arithmetic operators, +, -, *, /
• Circle parenthesis ( , )
we want me use stack to solve it
Here some examples about how your program should work:
2 - 3 * 4 + 2 -8
(5 + (11-5) * 2) * 4 + 9.9 77.9
2 + 3 = 5 Error: Undefined symbol '='
(5 + (11-5 * 2) * 4 + 9 Error: Missing parenthesis ')'
7* (8-2)) Error: Missing parenthesis '('
6*3e9 Error: Undefined symbol 'e'
2/[7+5] Error: Undefined symbol '[',’]’
my try code is
Code:
#include <iostream>
#include "hyjh.h"
using namespace std;
string ab ;
Stack <string> stack;
void read()
{
cout<<"enter the equation";
getline(cin,ab);
}
void check()
{
for(int i=1;i < ab.length();i++)
{
if if(ab[i]<=9 || ab[i]>=0 ||ab[i]=='+'||ab[i]=='*')
{
if(ab[i] == "*")
{
cout<<"true";
}
else
cout<<"false";
}
}
}
void parnt()
{
for(int i=1;i < ab.length();i++)
{
if(ab[i]=="(")
{
stack.pushstack(ab[i]);
}
if(ab[i]==")")
{
if( stack.emptystack())
{
cout<<"the stack empty";
else
stack.popstack(ab[i]);
}
}
if (!stack.emptystack())
{
cout<<"opening parenthesis not match";
}
}
}
void postfix()
{
for(int i=1;i < ab.length();i++) {
if(ab[i]=="(")
{
stack.pushStack(ab[i]);
}
else
if(ab[i]==")")
{
stack.popStack(ab[i]);
while(ab[i] !="(")
{
stack.popStack(ab[i]);
}
}
else
if(ab[i]=="+"||"*"||"/"||"-")
{
stack.stacktop(ab[i]);
if(stack.stacktop(ab[i])=="*"||"/" && ab[i] =="+"||"-" )
{
stack.popstack(ab[i]);
}
else
if(stack.stacktop(ab[i])=="+"||"-" && ab[i] =="*"||"/")
{
stack.pushstack(ab[i]);
}
else
if (stack.stacktop(ab[i])== ab[i])
{
stack.popstack(ab[i]);
}
}
while(!stack.emptystack())
{
stack.popstack(ab[i]);
}
}
}
void eval()
{
int val;
for(int i=0;i!='\0';i++)
{
if(ab[i]>=0 || ab[i]<=9)
{
stack.pushstack(ab[i]);
}
else
if(ab[i] == "+" )
{
stack.popstack(ab[i]);
stack.popstack(ab[i]);
val= ab[i] + ab[i] ;
stack.pushstack(val);
}
else
if(ab[i] == "-")
{
stack.popstack(ab[i]);
stack.popstack(ab[i]);
val= ab[i] - ab[i] ;
stack.pushstack(val);
}
else
if(ab[i] == "*")
{
stack.popstack(ab[i]);
stack.popstack(ab[i]);
val= ab[i] * ab[i] ;
stack.pushstack(val);
}
else
if(ab[i] == "/")
{
stack.popstack(ab[i]);
stack.popStack(ab[i]);
val= ab[i] / ab[i] ;
stack.pushstack(val);
}
}
stack.popStack(ab[i]);
}
}
int main()
{
read();
check();
postfix();
eval();
return 0;
}