Program won't detect/use double

This program finds the area of a rectangle. Double getWidth isn't cooperating with me, keeps saying that it's incompatible with double getWidth() (line 42). What am I doing wrong? I feel like it's a syntax error but I've been flipping around different ways to do it for a while now, so I'm not really sure.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "pch.h"
#include <iostream>
using namespace std;

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

int main()
{
	double length;
	double width;
	double area;

	length = getLength();
	width = getWidth();
	area = getArea(length, width);

	displayData(length, width, area);

	system("pause");
	return 0;
}

double getLength()
{
	double inputL;

	cout << "Length: ";
	cin >> inputL;

	while (inputL <= 0)
	{
		cout << "Length cannot be zero. Try again: ";
		cin >> inputL;
	}

	return inputL;
}

double getWidth()
{
	double inputW;

	cout << "Width: ";
	cin >> inputW;

	while (inputW <= 0)
	{
		cout << "Width cannot be zero. Try again: ";
		cin >> inputW;
	}

	return inputW;
}

double getWidth()
{
	double inputW;

	cout << "Width: ";
	cin >> inputW;

	while (inputW <= 0)
	{
		cout << "Width cannot be zero. Try again: ";
		cin >> inputW;
	}

	return inputW;
}

double getArea(double inputL, double inputW)
{
	double outputA;

	outputA = inputL * inputW;
	return outputA;
}

void displayData(double inputL, double inputW, double outputA)
{

	cout << "Area of rectangle: " << outputA << endl;

}
Your error messages are pretty self-explanatory.

Line 6
double getWidth; Defines a double variable

Line 42
double getWidth() Defines a double-returning function

Spot the inconsistency?


Oh and then ...

Line 58
double getWidth() Defines the entire function again


Last edited on
Hi,

There is a typo on line 6.

You have defined getWidth identically twice. A copy paste error?
Topic archived. No new replies allowed.