Thread: error expected initialized before bool

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    1

    error expected initialized before bool

    I got this error in the following program for line 22, and I do not know how to fix it.

    Code:
    // Brett Balzer
    // Converting to binary
    // 11/01/06
    
    #include <iostream>
    
    using namespace std;
    
    struct stack
    {
       int count;
       struct node *top; 
    };
    
    struct node
    {
       int data;
       struct node *next;
    };
    
    bool pushStack (struct stack *stack, int data)
    bool popStack (struct stack *stack, int &data)
    
    int main()
    {
        int number;
        int digit;
        struct stack theStack;
        struct stack *stack; 
        stack = &theStack;
    
        cout << "Enter a decimal number" << endl;
        cin >> number;
       
        while (number > 0)
        {
          digit = number % 2;
          number = number/2;
          pushOK = pushStack (stack, digit);
    
          if (pushOK == false)
          {
            cout << "Stack overflow creating digit" << endl;
            return 0;
          }
          
         }
            
        while (stack->top != NULL)
        {
          popStack (stack, digit);
          cout << digit;
        }
    
    return 0; 
    }
    
      bool pushStack (struct stack *stack, int data)
      {
        bool success;
    
        struct node *newptr;
        newptr = new struct node;
        newptr->data = data;
        newptr->next = stack->top;
        stack->top = newptr;
        stack->count = stack->count + 1;
        success = true;
        return success;
      } 
    
      bool popStack (struct stack *stack, int &data)
      {
        bool success;
    
        struct node *dltPtr;
       
        if (stack->top == NULL)
        {
          success = false;
        }
        else
        {
          dltPtr = stack->top;
          data = stack->top->data;
          stack->top = stack->top->next;
          stack->count = stack->count - 1;
          free (dltPtr);
          success = true;
         }
       }
    thank you very much!

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    add ; after function declaration
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing params between managed c++ and unmanaged c++
    By cechen in forum C++ Programming
    Replies: 11
    Last Post: 02-03-2009, 08:46 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  5. Need Help With an RPG Style Game
    By JayDog in forum Game Programming
    Replies: 6
    Last Post: 03-30-2003, 08:43 PM