Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-29-2008, 07:41 AM
debug debug is offline
Newbie
 
Join Date: Aug 2007
Posts: 17
Rep Power: 5
debug is on a distinguished road
Default 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 07:57 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 02-29-2008, 07:59 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

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";
	}
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 07:49 PM
debug debug is offline
Newbie
 
Join Date: Aug 2007
Posts: 17
Rep Power: 5
debug is on a distinguished road
Default

thks for the reply but if i use balance == false, i will get some kind of run time error.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2008, 11:22 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,421
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

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 | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DB inconsistency check eracha Database & Database Programming 3 02-29-2008 11:53 AM
Check My Blog Deathcry Site Reviews 7 01-14-2008 09:57 PM
Check object for null Lop C# Programming 3 07-18-2006 06:56 AM
CAPTCHA Check Jonas PHP Forum 0 07-15-2006 08:22 PM
More Coding Methods RobSoftware General Programming 2 05-30-2006 05:42 PM


All times are GMT -5. The time now is 11:24 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 101%


Complete - Celebrate!

Ads