Try to put your code between code tags. The code tag(s) is the # symbol in the little tool box to the right of the edit window when you are making a post.
Your 'problem' is straight forward.
First you are asking the user for the
Length then the
Width and you are storing
the values in
LOCAL variables in the main function.
You have a getArea function that takes no parameters - so the getArea function does not get the Length and Width values in order to calculate the area.
You can do the following.
Make two
overloaded versions of the
getArea function. One version takes no parameters and will ask the user for the Length and Width values.
The other version will take two parameters - one for the length and one for the Width.
You can then choose which version to use depending on whether you already have the Length/Width values or not.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
//Overloading the getArea function
//this version if you already have the length & width values
double getArea(double length, double width)
{
return length * width;
}
//this version if you want to get the length and with values from the user
double getArea()
{
return getLength() * getWidth();
}
|
**EDIT**
But I just realised thet this overloading could cause a problem with the
displayData(length, width, area); function because you need the length and width.
So it would be best to stick with just the
1 2 3 4
|
double getArea(double length, double width)
{
return length * width;
}
|
So your main function will look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
int main()
{
double length, // The rectangle's length, width, area.
width,
area;
// Get the rectangle's length.
length = getLength();
// Get the rectangle's width.
width = getWidth();
// Get the rectangle's area.
area = getArea(length, width); //<======
// Display the rectangle's data.
displayData(length, width, area);
|