Program not displaying area!

I'm new to programming! I'm trying to calculate the area of a rectangle with the length and width already passed as parameters (6, 4), but all my program does so far is display the message, but not calculate anything. Not sure if I called the function getArea properly in my main? Or is it something else? Any help would be great!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <iostream>
using namespace std;

double getArea(double length, double width)
{
	double area;

	// Calculate and return area
	area = length * width;

	return area;

}

int main(){

	// Display area
	cout << "Area of rectangle is: " << getArea << endl;

	// Call getArea function
	getArea(6, 4);

	return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
 #include <iostream>
using namespace std;
double getArea(double length, double width)
{
	return length * width;
}

int main()
{
	cout << "Area of rectangle is: " << getArea(6,4) << endl;
        return 0;
}


getArea is defined as a function, it is therefore why you must pass arguments to it every time you call it.

Why would you expect the program to go to line 21 before all others first, remember the value the defined function returned and then display it among with the comment in line 18?
Last edited on
Topic archived. No new replies allowed.