whats wrong with this??

This is a discussion on whats wrong with this?? within the C++ Programming forums, part of the General Programming Boards category; sorry to keep asking about my crappy programs but im learning so its anoying lol. its from a book im ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    132

    whats wrong with this??

    sorry to keep asking about my crappy programs but im learning so its anoying lol.
    its from a book im reading but it dont work, i cannot fix it lol.

    any ideas, the errors are below the code.


    Code:
    #include <iostream>
    
    using namespace std;
    
    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);
    
    void 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)
    		{
    			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;
    
    			cout <<"\nNew width: ";
    			cin >> newWidth;
    			cout <<"\nNew height: ";
    			cin >> newLength;
    				theRect.SetSize(newWidth, newLength);
    			DoDrawRect(theRect);
    			break;
    		default:
    			cout <<"Error in choice!\n";
    			fQuit = TRUE;
    			break;
    		}
    	}
    }
    
    USHORT DoMenu()
    {
    	USHORT choice;
    	cout <<"\n\n **** Menu **** \n";
    	cout <<"(1) Draw Rectangle \n";
    	cout <<"(2) Area \n";
    	cout <<"(3) Perimeter \n";
    	cout <<"(4) Resize \n";
    	cout <<"(5) Quit \n";
    
    	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++)
    			cout <<"*";
    		cout <<"\n";
    	}
    }
    
    void DoGetArea(Rectangle theRect)
    {
    	cout <<"Area: " << theRect.GetArea() << endl;
    }
    
    void DoGetPerim(Rectangle theRect)
    {
    	cout <<"Perimeter: " << theRect.GetPerim << endl;
    }
    Code:
    ------ Build started: Project: big test, Configuration: Debug Win32 ------
    Compiling...
    big test.cpp
    .\big test.cpp(50) : error C3646: 'USHORT' : unknown override specifier
    .\big test.cpp(50) : error C3646: 'DoMenu' : unknown override specifier
    .\big test.cpp(50) : error C2091: function returns function
    .\big test.cpp(50) : error C2761: 'Rectangle::~Rectangle(void)' : member function redeclaration not allowed
    .\big test.cpp(65) : error C3861: 'DoMenu': identifier not found
    .\big test.cpp(101) : error C2365: 'DoMenu' : redefinition; previous definition was 'formerly unknown identifier'
    .\big test.cpp(134) : error C3867: 'Rectangle::GetPerim': function call missing argument list; use '&Rectangle::GetPerim' to create a pointer to member
    Build log was saved at "file://c:\Documents and Settings\Reece.YOUR-E0367A1424\My Documents\Visual Studio 2005\Projects\big test\big test\Debug\BuildLog.htm"
    big test - 7 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    please help. cheers in advance. reece.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    1) It's int main(), not void main().
    2) You have enum constants of the same name as some functions. They conflict.
    3) The definition of ~Rectangle is missing the braces.
    4) You need to declare functions before using them. (DoMenu() error on line 65)
    5) (Line 134) Missing argument list: exactly what the error message says.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    cheers mate it worked.
    shame the program was pretty useless lmao.

    it says void main in the book. so some compilers accept it?

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Some crazy compilers might, but we like code that all compilers like. That code is
    Code:
    int main() {}
    *drools*
    Last edited by SlyMaelstrom; 06-07-2006 at 05:50 AM.
    Sent from my iPadŽ

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,113
    it says void main in the book. so some compilers accept it?
    Yes, but it is nonetheless non-standard.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    it says void main in the book. so some compilers accept it?
    Please read this faq:

    http://faq.cprogramming.com/cgi-bin/...&id=1043284376
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 04:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 01:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 02:04 PM

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