Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help! it\'s not compiling.. #include \"IntStack.h\" #include <iostream> u

ID: 3821734 • Letter: P

Question

Please help! it's not compiling..

#include "IntStack.h"
#include <iostream>

using namespace std;


int main()
    {
        int catchVar; // To hold values popped off the stack

       // Create a MathStack object.
       MathStack stack(5);

       // Push 3 and 6 onto the stack.
       cout << "Pushing 3 ";
       Stack.push(3);
       cout << "Pushing 6 ";
       stack.push(6);

       // Add the two values.
       stack.add();

       // Pop the sum off the stack and display it.
       cout << "The sum is ";
       stack.pop(catchVar);
       cout << catchVar << endl << endl;

       // Push 7 and 10 onto the stack
       cout << "Pushing 7 ";
       stack.push(7);
       cout << "Pushing 10 ";
       stack.push(10);

       // Subtract 7 from 10.
       stack.sub();

       // Pop the difference off the stack and display it.
       cout << "The difference is ";
       stack.pop(catchVar);
       cout << catchVar << endl;
       return 0;
   }

Explanation / Answer


#include <iostream>

#include "MathStack.h"

using namespace std;


int main()
    {
        int catchVar; // To hold values popped off the stack

       // Create a MathStack object.
       MathStack stack(5);

       // Push 3 and 6 onto the stack.
       cout << "Pushing 3 ";
       Stack.push(3);
       cout << "Pushing 6 ";
       stack.push(6);

       // Add the two values.
       stack.add();

       // Pop the sum off the stack and display it.
       cout << "The sum is ";
       stack.pop(catchVar);
       cout << catchVar << endl << endl;

       // Push 7 and 10 onto the stack
       cout << "Pushing 7 ";
       stack.push(7);
       cout << "Pushing 10 ";
       stack.push(10);

       // Subtract 7 from 10.
       stack.sub();

       // Pop the difference off the stack and display it.
       cout << "The difference is ";
       stack.pop(catchVar);
       cout << catchVar << endl;
       return 0;
   }

OUTPUT:

PUSHING 3

PUSHING 6

THE SUM IS 9

PUSHING 7

PUSHING 10

THE DIFFERENCE IS 3