Question:
Can somebody find out my error in this program?
anonymous
2012-03-23 10:25:02 UTC
C++
The syntax error is that at the last function it declares the double length as a shadow parameter and same for width and area.

#include
using namespace std;

double getLength();
double getWidth();
double getArea();
double displayData(double, double, double);

int main()
{
double length, // The rectangle's length
width, // The rectangle's width
area; // The rectangle's area

// Get the rectangle's length.
length = getLength();

// Get the rectangle's width.
width = getWidth();

// Get the rectangle's area.
area = getArea();

// Display the rectangle's data.
displayData(length, width, area);

system("pause");
return 0;
}

//*****************************************************************************
// Purpose: Prompt and display the length of the rectangle
// Date: March 23, 2012
//*****************************************************************************
double getLength(double)
{
//declare variables
double length;

//prompt the user
cout << "Enter the length of the rectangle: ";
cin >> length;

//return value
return length;
}
//****************************************************************************
// Purpose: Prompt and display the width of the rectangle
// Date: March 23, 2012
//****************************************************************************
double getWidth(double)
{
//declare variables
double width;

//prompt the user
cout << "Enter the width of the rectangle: ";
cin >> width;

//return value
return width;
}
//*****************************************************************************
// Purpose: Calculate the area of the rectangle
// Date: March 23, 2012
//*****************************************************************************
double getArea(double)
{
//declare variables
double area,
length,
width;

//calculate the area
area = length * width;

//return value
return area;
}
//*****************************************************************************
// Purpose: Display the data
// Date: March 23, 2012
//*****************************************************************************
double displayData(double length, double width, double area)
{
//declare variables
double length,
width,
area;

//display the area
cout << "The length is " << length
<< "The width is " << width
<< "The area is " << area
<< endl;

//return value
return length, width, area;
}
Three answers:
skatero00778
2012-03-23 10:33:27 UTC
On your functions declaration quit the double

example

not use double getArea(double)

use double getArea()

do this for

double getWidth()

double getLength()
shywolf91
2012-03-23 10:32:53 UTC
I ran the code in codebloacks:



Here are the errors I got:



errors on line(s): 87-89.





also got error about system not being defined



I would try searching google with the error you got also check cplusplus.com
Dry_rubber_Chicken
2012-03-23 10:49:26 UTC
It is in your best interest to turn on line numbers and learn how to hunt errors yourself.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...