Thread: hmm help-

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    25

    hmm help-

    Ok im having trouble compiling this. Its exactly what the book has written. I know that this book is out of standard (teach yourself c++ in 21 days).

    Code:
      #include <iostream>
    
      typedef unsigned short int USHORT;
      typedef unsigned long int ULONG;
      enum BOOL { FALSE, TRUE};
      enum CHOICE { DrawRect = 1, GetArea, 
         GetPerim, ChangeDimensions, Quit};
      // Rectangle class declaration
      class Rectangle
     {
        public:
          // constructors
          Rectangle(USHORT width, USHORT height);
          ~Rectangle();
    
          // accessors
          USHORT GetHeight() const { return itsHeight; }
          USHORT GetWidth() const { return itsWidth; }
          ULONG GetArea() const { return itsHeight * itsWidth; }
          ULONG GetPerim() const { return 2*itsHeight + 2*itsWidth; }
          void SetSize(USHORT newWidth, USHORT newHeight);
    
          // Misc. methods
          void DrawShape() const;
    
        private:
          USHORT itsWidth;
          USHORT itsHeight;
     };
    
     // Class method implementations
     void Rectangle::SetSize(USHORT newWidth, USHORT newHeight)
     {
        itsWidth = newWidth;
        itsHeight = newHeight;
     }
    
    
     Rectangle::Rectangle(USHORT width, USHORT height)
     {
        itsWidth = width;
        itsHeight = height;
     }
    
     Rectangle::~Rectangle() {}
    
     USHORT DoMenu();
     void DoDrawRect(Rectangle);
     void DoGetArea(Rectangle);
     void DoGetPerim(Rectangle);
    
     int main ()
     {
        // initialize a rectangle to 10,20
        Rectangle theRect(30,5);
    
        USHORT choice = DrawRect;
        USHORT fQuit = FALSE;
    
        while (!fQuit)
        {
          choice = DoMenu();
          if (choice < DrawRect || choice >  Quit)
          {
            std::cout << "\nInvalid Choice, please try again.\n\n";
            continue;
          }
          switch (choice)
          {
          case  DrawRect:
            DoDrawRect(theRect);
            break;
          case GetArea:
            DoGetArea(theRect);
            break;
          case GetPerim:
            DoGetPerim(theRect);
            break;
          case ChangeDimensions:
            USHORT newLength, newWidth;
            std::cout << "\nNew width: ";
            std::cin >> newWidth;
            std::cout << "New height: ";
            std::cin >> newLength;
            theRect.SetSize(newWidth, newLength);
            DoDrawRect(theRect);
            break;
          case Quit:
            fQuit = TRUE;
            std::cout << "\nExiting...\n\n";
            break;
          default:
            std::cout << "Error in choice!\n";
            fQuit = TRUE;
            break;
          }   // end switch
        }     // end while
        return 0;
     }       // end main
    
    
     USHORT DoMenu()
     {
       USHORT choice;
        std::cout << "\n\n   *** Menu *** \n";
        std::cout << "(1) Draw Rectangle\n";
        std::cout << "(2) Area\n";
        std::cout << "(3) Perimeter\n";
        std::cout << "(4) Resize\n";
        std::cout << "(5) Quit\n";
    
      std::cin >> choice;
      return choice;
     }
    
     void DoDrawRect(Rectangle theRect)
     {
       USHORT height = theRect.GetHeight();
       USHORT width = theRect.GetWidth();
    
       for (USHORT i = 0; i<height; i++)
       {
         for (USHORT j = 0; j< width; j++)
           std::cout << "*";
         std::cout << "\n";
       }
     }
    
    
     void DoGetArea(Rectangle theRect)
     {
       std::cout << "Area: " <<  theRect.GetArea() << std::endl;
     }
    
     void DoGetPerim(Rectangle theRect)
     {
       std::cout << "Perimeter: " <<  theRect.GetPerim() << std::endl;
     }
    COMPILER: DEV C++ (newest beta version)
    ERRORS:
    5 parse error before numeric constant
    48 variable or field `DoDrawRect' declared
    48 invalid conversion from `BOOL (*)(HDC__*,
    49 variable or field `DoGetArea' declared
    49 invalid conversion from `BOOL (*)(HDC__*,
    50 variable or field `DoGetPerim' declared
    50 invalid conversion from `BOOL (*)(HDC__*,
    [Warning] In function `int main()':
    55 `Rectangle' undeclared (first use this

    ++. many more.

    Thanks,
    arnis

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Are those the only includes you have?
    It works fine here, too.

    Some of those, though, lead me to believe you either have a windows project going, or included <windows.h> -- your program shouldn't even know the existence of HDC, a typedef for HDC__* that is windows-specific. That also might explain FALSE and TRUE errors, if they're already defined. That error seems to indicate that FALSE is a #define for 0, TRUE a #define for 1, which makes the enum evaluate to

    enum BOOL { 0, 1};

    which of course is illegal.

    In fact, if I add #include <windows.h> I get errors at all the same places as you.
    Last edited by Cat; 07-20-2003 at 10:10 AM.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    25
    Yes that's the only include i have.
    If i comment out the enum bool part. I get one less error.

    It's not a windows project so its very strange.
    Maybe windows.h is included automatic in the newest beta version of Dev c++ for some reason.

    This ........es me off

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    Have you downloaded the Borland 5.5 C++ compiler to try against that? As it's a free download from Borlands website, it would be a good test.

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Probably some option you have set somewhere. I'll play around with Dev when I get home later to see what it might be.

    Might want to check in "Compiler Options" though for anything that might be linked in that seems out of place.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  6. #6
    Registered User
    Join Date
    Jul 2003
    Posts
    17
    It works fine on Dev-C++ 4.01.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation Fault hmm?
    By pobri19 in forum C Programming
    Replies: 4
    Last Post: 05-03-2008, 07:51 AM
  2. hmm i think i broke something (power supply)
    By MisterSako in forum Tech Board
    Replies: 1
    Last Post: 02-11-2006, 11:32 PM
  3. hmm, easy problem from by book.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 01-07-2003, 11:14 PM
  4. hmm.....
    By D4050 in forum C++ Programming
    Replies: 4
    Last Post: 10-03-2001, 02:13 PM
  5. hmm, newbie AGAIN? ;)
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-05-2001, 08:17 AM