What is wrong with this code? It's not running. It compiles okay but when I run it, it simply says, "Press any key to continue . . .". Please help me with it. Thank you.
#include <iostream>
using namespace std;
#include <cstdlib>
#include <string>
const int MAX = 10;
////////////////////////////////////////////////////////////////
class Stack
{
protected:
//static const int MAX=10;
int st[MAX];
int top;
public:
Stack(): top(-1)
{/*empty body*/}
void push(int var)
{ st[++top] = var; }
int pop()
{ return st[top--]; }
};
////////////////////////////////////////////////////////////////
class Stack2 : public Stack
{
public:
void push(int var)
{
if(top >= MAX-1) // (MAX-1) because array starts from 0
{ cout << "\nError: stack is full"; exit(1); }
Stack::push(var);
}
int pop()
{
if(top < 0)
{ cout << "\nError: stack is empty\n"; exit(1); }
return Stack::pop();
}
};
////////////////////////////////////////////////////////////////
int main()
{
Stack2 s1; int stackvar; int count = -1;
for(int i=0; i>=(MAX-1); i++)
{
cout << "enter the number into stack: "; cin >> stackvar;
s1.push(stackvar);
count++;
}
cout << endl;
while(count != -1)
{
s1.pop();
count--;
}
cout << endl;
system("pause;");
return 0;
}


Sign In
Create Account


Back to top









