User defined functions

Hi, I am having a problem with one of my tasks. I am asked to find and display the time required to mow the grass around a house. The house has a square shape and the plot of grass has a rectangular shape. Here is my code. I dont know why but i keep getting this error: error C2447: '{' : missing function header (old-style formal list?) Also the code must contain functions with parameters.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  #include <iostream>
using namespace std;

double area(double x, double y);

int main()
{
	double width, length,side,rate,time, fullArea;
	

	cout << "what is the width?" << endl;
	cin >> width;
	cout << "what is the length?" << endl;
	cin >> length;
	cout << "what is the side value?" << endl;
	cin >> side;

	double rectangleArea;
	rectangleArea = area(width, length);
	
	double squareArea;
	squareArea = area(side, side);
	
	
	fullArea = rectangleArea - squareArea;

	
	cout << "the Area is " << fullArea << " square metres" << endl;
	cout << endl;
    cout << "what is the rate?" << endl;
	cin >> rate;
	time = fullArea / rate;
	cout << "The mowing time required to cut the grass around a house is " << time << " minutes" << endl;
	return 0;
}
   double area(double x, double y);
{                                     // this is where the error is.
	double z;
	z = x*y;
	return z;

}
Hey :)

1
2
3
4
5
6
7
 double area(double x, double y); // you have semicolon here, remove it =)
{                                    
	double z;
	z = x*y;
	return z;

}
Hi,

Remove the semicolon from line 36 :+)
Line 36.
double area(double x, double y);
No need for that semicolon, that's a function definition, so remove it.
You put ';' only when you want to declare a function, like in line 4.

...third... :D
Last edited on
It helped. Thank you very much.
Topic archived. No new replies allowed.