+ Reply to Thread
Results 1 to 4 of 4

Thread: need someone to check my coding

  1. #1
    Newbie debug is an unknown quantity at this point
    Join Date
    Aug 2007
    Posts
    17

    need someone to check my coding

    im writing a stack to check for parenthesis but the output alway read " expression not match" even if the stack is balanced. hope someone can see what is wrong with my program.below is the coding
    Code:
    #include <iostream>
    #define STACKSIZE 80
    #define TRUE 1
    #define FALSE 0
    
    using namespace std;
    
    void StackInit();
    int IsStackEmpty();
    int IsStackFull();
    int StackPush(char c);
    char StackPop();
    char ViewStackTop();
    
    char myStack[STACKSIZE];
    int top;
    
    int main()
    {
    	char *c;
    	c = myStack;
    	int balance;
    
    	cout << " Please enter an equation:";
    	cin.getline(myStack, STACKSIZE);
    	for (int i = 0; i < STACKSIZE; i++)
    	{
    		if(*c == '(' || *c == '{' || *c == '[')
    		{
    			StackPush(*c);
    		}
    		else
    		{  
    			if(*c == ')' || *c == '}' || *c == ']')
    			{
    				if(IsStackEmpty() == TRUE)
    				{
    					balance = FALSE;
    				}
    				else
    				{
    					StackPop();
    				}
    			}
    		}
    	}
    
    	if(balance = FALSE)
    	{
    		cout << "Result: Expression not match";
    	}
    	else
    	{
    		if(!IsStackEmpty())
    		{
    			cout << "Result: Expression not match";
    		}
    		else
    		{
    			cout << "Result Expression is vaild";
    		}
    	}
    
         system("pause");
         return 0;
    }
    
    void StackInit()
    {
      top = -1;
    }
    
    int IsStackEmpty()
    {
      if (top == -1)
        return TRUE;
      return FALSE;
    }
    
    int IsStackFull()
    {
      if (top == (STACKSIZE - 1))
        return TRUE;
      return FALSE;
    }
    
    int StackPush(char c)
    {
      if (top == (STACKSIZE - 1))
        return FALSE;
      myStack[++top] = c;
      return TRUE;
    }
    
    char StackPop()
    {
      if (top == -1)
        return '\0';
      return myStack[top--];
    }
    
    char ViewStackTop()
    {
      if (top == -1)
        return '\0';
      return myStack[top];
    }
    Last edited by v0id; 02-29-2008 at 06:57 AM.

  2. #2
    Retired v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light
    Join Date
    Apr 2007
    Posts
    2,978
    Blog Entries
    3
    Please use code-tags in the future.

    I didn't go through the whole code, but I noticed how you're trying to compare balance with FALSE, in one of the if-statements.
    Code:
    	if(balance = FALSE)
    	{
    		cout << "Result: Expression not match";
    	}
    You're not comparing, but assigning. This should of course be:
    Code:
    	if(balance == FALSE)
    	{
    		cout << "Result: Expression not match";
    	}

  3. #3
    Newbie debug is an unknown quantity at this point
    Join Date
    Aug 2007
    Posts
    17
    thks for the reply but if i use balance == false, i will get some kind of run time error.

  4. #4
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,697
    Blog Entries
    57
    Getting a runtime error just tells you that you have another error in your code. Not getting runtime errors doesn't mean it's correct.
    CodeCall Blog | CodeCall Wiki | Shareware
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. DB inconsistency check
    By eracha in forum Database & Database Programming
    Replies: 3
    Last Post: 02-29-2008, 10:53 AM
  2. Check My Blog
    By Deathcry in forum Site Reviews
    Replies: 7
    Last Post: 01-14-2008, 08:57 PM
  3. Check object for null
    By Lop in forum C# Programming
    Replies: 3
    Last Post: 07-18-2006, 05:56 AM
  4. CAPTCHA Check
    By Jonas in forum PHP Forum
    Replies: 0
    Last Post: 07-15-2006, 07:22 PM
  5. More Coding Methods
    By RobSoftware in forum General Programming
    Replies: 2
    Last Post: 05-30-2006, 04:42 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts