|
||||||
| 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. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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. |
| Sponsored Links |
|
|
|
|||||
|
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. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |
| 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 |