please help me in this code

This is a discussion on please help me in this code within the C++ Programming forums, part of the General Programming Boards category; HELLO EVERY ONE HOW ARE YOU? i want you to help me please i have question and i am try ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    1

    Lightbulb 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;
     	}

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,305
    You haven't asked a question, you've just posted the assignment details.
    You need to give far better information than "compiler is not work" [sic].
    You need to state exactly what the problem is, with exact error messages.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-10-2010, 10:28 AM
  2. Replies: 14
    Last Post: 04-01-2008, 02:23 AM
  3. producing c/c++ code from flowcharts,pseudo code , algorithims
    By rohit83.ken in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2008, 06:09 AM
  4. Having trouble translating psudeo-code to real-code.
    By Lithorien in forum C++ Programming
    Replies: 13
    Last Post: 10-05-2004, 07:51 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21