probs with a simple program

C

Claus Nietzsche

hey people,
i wrote this program, but i have troubles compiling it.
my compiler keeps giving me error messages in this one line, and i cant
figure out why.
its in the line: void DoDrawRect(Rectangle);


#include <iostream>
using namespace std;

enum choice { DrawRect = 1, GetArea, GetPerim, ChangeDimensions, Quit};

class Rectangle
{
public:
Rectangle(int width, int height);
~Rectangle();

int GetWidth() {return itsWidth;}
int GetHeight() {return itsHeight;}
int GetArea() {return (itsWidth*itsHeight);}
int GetPerim() {return (2*itsWidth+2*itsHeight);}
void SetSize(int width, int height);

private:
int itsWidth;
int itsHeight;
};

Rectangle::Rectangle(int width, int height)
{
itsWidth=width;
itsHeight=height;
}

Rectangle::~Rectangle() {}

void Rectangle::SetSize(int width, int height)
{
itsWidth=width;
itsHeight=height;
}

int DoMenu();
void DoDrawRect(Rectangle); // <<--HERES THE
PROBLEM!!!!!!!!!!!!!!!!
void DoGetArea(Rectangle);
void DoGetPerim(Rectangle);

int main()
{
Rectangle theRect(30,5);

int choice=DrawRect;
int fQuit=false;

while(!fQuit)
{
choice=DoMenu();
if (choice<DrawRect || choice>Quit)
{
cout << "\nAuswahl ungueltig. Bitte neu versuchen.\n\n";
continue;
}
switch(choice)
{
case DrawRect:
DoDrawRect(theRect);
break;
case GetArea:
DoGetArea(theRect);
break;
case GetPerim:
DoGetPerim(theRect);
break;
case ChangeDimensions:
int newWidth, newHeight;
cout << "\nBitte geben Sie die Breite an: ";
cin << newWidth;
cout << "\nBitte geben Sie die Hoehe an: ";
cin << newHeight;
theRect.SetSize(newWidth, newHeight);
DoDrawRect(theRect);
break;
case Quit:
fQuit=true;
cout << "\nVerlassen.\n";
break;
default:
cout << "\nFehler beim Auswaehlen!\n";
fQuit=true;
break;
}
return 0;
}

int DoMenu()
{
int choice;
cout << "\n\n**** Menue ****\n";
cout << "(1) Rechteck zeichnen\n";
cout << "(2) Flaeche\n";
cout << "(3) Umfang\n";
cout << "(4) Groesse veraendern\n";
cout << "(5) Beenden\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 << "x";
cout << endl;
}
}

void DoGetArea(Rectangle theRect)
{
int area=theRect.GetArea();
cout << "Flaeche: " << area << endl;
}

void DoGetPerim(Rectangle theRect)
{
int perim=theRect.GetPerim();
cout << "Umfang: " << perim << endl;
}

id really appreciate any help,
bye,
Claus
 
R

Rob Williscroft

Claus Nietzsche wrote in
hey people,
i wrote this program, but i have troubles compiling it.
my compiler keeps giving me error messages in this one line, and i cant
figure out why.
its in the line: void DoDrawRect(Rectangle);


[snip]

int main()
{
Rectangle theRect(30,5);

int choice=DrawRect;
int fQuit=false;

while(!fQuit)
{
choice=DoMenu();
if (choice<DrawRect || choice>Quit)
{
cout << "\nAuswahl ungueltig. Bitte neu versuchen.\n\n";
continue;
}
switch(choice)
{
case DrawRect:
DoDrawRect(theRect);
break;
case GetArea:
DoGetArea(theRect);
break;
case GetPerim:
DoGetPerim(theRect);
break;
case ChangeDimensions:
int newWidth, newHeight;
cout << "\nBitte geben Sie die Breite an: ";
cin << newWidth;

cin >> newWidth;

cout << "\nBitte geben Sie die Hoehe an: ";
cin << newHeight;

cin >> newHeight;

theRect.SetSize(newWidth, newHeight);
DoDrawRect(theRect);
break;
case Quit:
fQuit=true;
cout << "\nVerlassen.\n";
break;
default:
cout << "\nFehler beim Auswaehlen!\n";
fQuit=true;
break;
}

} /* end the while loop */
return 0;
}

[snip]


id really appreciate any help,
bye,
Claus

The above were the only error's I could find.

After applying the fixes it compiled and ran on 4 out of 4 of the
compilers I tried.

HTH.

Rob.
 
V

Victor Bazarov

Claus Nietzsche said:
hey people,
i wrote this program, but i have troubles compiling it.
my compiler keeps giving me error messages in this one line, and i cant
figure out why.

WHAT error?
its in the line: void DoDrawRect(Rectangle);


#include <iostream>
using namespace std;

enum choice { DrawRect = 1, GetArea, GetPerim, ChangeDimensions, Quit};

class Rectangle
{
public:
Rectangle(int width, int height);
~Rectangle();

int GetWidth() {return itsWidth;}
int GetHeight() {return itsHeight;}
int GetArea() {return (itsWidth*itsHeight);}
int GetPerim() {return (2*itsWidth+2*itsHeight);}
void SetSize(int width, int height);

private:
int itsWidth;
int itsHeight;
};

Rectangle::Rectangle(int width, int height)
{
itsWidth=width;
itsHeight=height;
}

Rectangle::~Rectangle() {}

void Rectangle::SetSize(int width, int height)
{
itsWidth=width;
itsHeight=height;
}

int DoMenu();
void DoDrawRect(Rectangle); // <<--HERES THE
PROBLEM!!!!!!!!!!!!!!!!
void DoGetArea(Rectangle);
void DoGetPerim(Rectangle);

int main()
{
Rectangle theRect(30,5);

int choice=DrawRect;
int fQuit=false;

while(!fQuit)
{
choice=DoMenu();
if (choice<DrawRect || choice>Quit)
{
cout << "\nAuswahl ungueltig. Bitte neu versuchen.\n\n";
continue;
}
switch(choice)
{
case DrawRect:
DoDrawRect(theRect);
break;
case GetArea:
DoGetArea(theRect);
break;
case GetPerim:
DoGetPerim(theRect);
break;
case ChangeDimensions:
int newWidth, newHeight;
cout << "\nBitte geben Sie die Breite an: ";
cin << newWidth;

This should probably be

cin >> newWidth;
cout << "\nBitte geben Sie die Hoehe an: ";
cin << newHeight;

And this
cin >> newHight;
theRect.SetSize(newWidth, newHeight);
DoDrawRect(theRect);
break;
case Quit:
fQuit=true;
cout << "\nVerlassen.\n";
break;
default:
cout << "\nFehler beim Auswaehlen!\n";
fQuit=true;
break;
}

You need another curly brace here, to close the "while" body:

}
 
C

Claus Nietzsche

first of all i wanna thank you for qour help.

so you mean that you didnt get any error message in the following line?
void DoDrawRect(Rectangle);???

which compilers did you try it on?
im using dev-c++ 4.9.8.0
 
C

Claus Nietzsche

the error message i get is the following:
C:/Documents and Settings/Albert/My Documents/C++/week1.cpp:38: variable or
field `DoDrawRect' declared void
C:/Documents and Settings/Albert/My Documents/C++/week1.cpp:38: invalid
conversion from `BOOL (*)(HDC__*, int, int, int, int)' to `int'

i changed the other mistakes (pretty dumb ones *g*)

but i still get that error!!
 
R

Rob Williscroft

Claus Nietzsche wrote in
first of all i wanna thank you for qour help.

so you mean that you didnt get any error message in the following line?
void DoDrawRect(Rectangle);???

That is correct.
which compilers did you try it on?
im using dev-c++ 4.9.8.0

That isn't a compiler its an IDE, it probably uses gcc as its compiler.

Read your Dev-c++ docs/help to find out what compiler its using.

One of the compiler's I tried was gcc 3.2.3.

Rob.
 
V

Victor Bazarov

Claus Nietzsche said:
first of all i wanna thank you for qour help.

so you mean that you didnt get any error message in the following line?
void DoDrawRect(Rectangle);???

No, we apparently didn't.
which compilers did you try it on?

Comeau online test-drive.
im using dev-c++ 4.9.8.0

Shouldn't be of any difference.

I have a suspicion, however. If your compiler includes <windows.h>
somewhere behind the scenes, unbeknownst to you, you may get some
kind of definition interference from MS Windows types.

Victor
 
C

Claus Nietzsche

so,
do u have any kind of advice for me?


Victor Bazarov said:
No, we apparently didn't.


Comeau online test-drive.


Shouldn't be of any difference.

I have a suspicion, however. If your compiler includes <windows.h>
somewhere behind the scenes, unbeknownst to you, you may get some
kind of definition interference from MS Windows types.

Victor
 
C

Claus Nietzsche

allright,
thx for all your help,
i really appreciate it.

i will try to use gnu 3.3.2 now
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top