i got some enum error cant find solution

This is a discussion on i got some enum error cant find solution within the C++ Programming forums, part of the General Programming Boards category; i tried retype the program that draw circle from the book beginner to c++ in 3 weeks but i cant ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    6

    i got some enum error cant find solution

    i tried retype the program that draw circle from the book beginner to c++ in 3 weeks
    but i cant get it to work, i have check from my code and the books code but i cant find the error the kompilator keep coming back to enum here is the kods

    Code:
    #include <iostream>
    using namespace std;
    enum CHOICE { DrawRect = 1, GetArea, 3: GetPerim, 
    ChangeDimensions, Quit};
    
    // Deklaration av klassen Rectangel
    
    class Rectangle
    
    {
          public:
                 //kontruerare
                 Rectangle(int width, int height);
                 ~Rectangle();
                 
                 //atkomster metoder
                 int GetHeight() const { return itsHeight;}
                 int GetWidth() const { return itsWidth;}
                 int GetArea() const { return itsHeight * itsWidth;}
                 int GetPerim() const { return 2 * itsHeight + 2 * itsWidth;}
                 void SetSize(int newWidth, int newHeight);
                 
                 //div.metoder
                 
          private:
                  
                  int itsWidth;
                  int itsHeight;
                  
                  
    };
    
    //Implementreing av klass metoder
    void Rectangle::SetSize(int newWidth, int newHeight)
    
    {
         itsWidth = newWidth;
         itsHeight = newHeight;
         
    }
    Rectangle::Rectangle(int width, int height)
    {
    
          itsWidth = width;
          itsHeight = height;
    }
    
    Rectangle::~Rectangle() {}
    
    int DoMenu();
    void DoDrawRect(Rectangle);
    void DoGetArea(Rectangle);
    void DoGetPerim(Rectangle);
    
    int main()
    {
        //initiera en rectangle till 30
        Rectangle theRect(30,5);
        
        int choice = DrawRect;
        int fQuit = false;
        
        while (!fQuit)
        
        {
              choice = DoMenu();
              if (choice < DrawRect || choice > Quit)
              
              {
                         cout << "\nOgiltig val, forsok igen. \n\n";
                         continue;
                         
                         }
                         switch (choice)
                         {
                         case DrawRect:
                              DoDrawRect(theRect);
                              break;
                         case GetArea:
                              DoGetArea(theRect);
                              break;
                         case GetPerim:
                              DoGetPerim(theRect);
                              break;
                         case ChangeDimension:
                              int newLength, newWidth;
                              cout <<"\nNy bredd: ";
                              cin >> newWidth;
                              cout << "Ny Hojd: ";
                              cin >> newLength;
                              theRect.SetSize(newWidth, newLength);
                              DoDrawRect(theRect);
                              break;
                         case Quit:
                              fQuit = true;
                              cout << "\nAvslutar...\n\n";
                              break;
                         default:
                               cout << "Fel i val\n";
                               fQuit = true;
                               break;
                               
                               }     // end switch
                               }     // end while               
                         return 0;
                         
    }                                // end main
    int DoMenu()
    
    {
        
        int choice;
        
        cout << "\n\n*******Meny*****\n";
        cout << "(1) Rita rektangeln\n";
        cout << "(2) Area\n";
        cout << "(3) Omkrets\n";
        cout << "(4) Andra Storlek\n";
        cout << "(5) Avslutar\n";
        
        cin >> choice;
        return choice;
        
    }
    void DoDrawRect(Rectangle theRect)
    {
         int height = theRect.GetHeight();
         int width = theRect.GetWidth();
        
        for (int i = 0; i<height; i++)
        
        {
            for(int j=0; j<width; j++)
            cout << "*";
            cout << "\n";
            
    }
    }
    
    void DoGetArea(Rectangle theRect)
    {
         cout << "Area: " << theRect.GetArea() << endl;
         
    }
    void DoGetPerim(Rectangle theRect)
    {
         cout << "Omkrets: " << theRect.GetPerim() << endl;
         }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,615
    It looks like this:
    Code:
    enum CHOICE { DrawRect = 1, GetArea, 3: GetPerim, 
    ChangeDimensions, Quit};
    should be:
    Code:
    enum CHOICE {DrawRect = 1, GetArea, GetPerim, ChangeDimensions, Quit};
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Chi! whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    8,189
    Well enum is typed incorrectly. You would do it like this:
    Code:
    enum CHOICE { DrawRect = 1, GetArea = 2, GetPerim = 3, 
    ChangeDimensions = 4, Quit = 5};
    Also you might not need to give enum an identifier ("CHOICE") unless you intend to use it as a type.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    i will try that , thanks alot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Free program I'm sharing: ConvertEnumToStrings
    By Programmer_P in forum Projects and Job Recruitment
    Replies: 101
    Last Post: 07-18-2010, 12:55 AM
  2. Member is private..??
    By Programmer_P in forum C++ Programming
    Replies: 35
    Last Post: 06-05-2010, 12:59 AM
  3. fscanf()
    By Maz in forum C Programming
    Replies: 15
    Last Post: 08-31-2009, 08:30 AM
  4. A basic question on enum
    By MasterM in forum C++ Programming
    Replies: 2
    Last Post: 06-12-2009, 09:16 PM
  5. Won't Return pointer, i can't find why...
    By ss3x in forum C++ Programming
    Replies: 2
    Last Post: 02-28-2002, 07:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21