I need help for a value by reference program

I need help for a value by reference program with the area of a rectange
Why doesn't my code work???
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
#include <iostream>
#include <iomanip>
using namespace std;

// Function prototypes 
double getLength();
double getWidth();
double getArea();
double displayData();

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

	cout << getLength();
	cout << getWidth();
	cout << getArea();
	cout << displayData();

	system("pause");
	return 0;

}// Get the rectangle's length.
	
double getLength() //Line 32
	{
		double length;
		cout << "Enter the length: ";
		cin >> length;
		return (length);
	}

	// Get the rectangle's width.
	double getWidth()//Line 40
	{
		double width;
		cout << "\nEnter the width: ";
		cin >> width;
		return (width);
	}

	// Get the rectangle's area.
	double getArea(double length, double width)
	{
		double area;
		area = (length * width);
		return (area);
	}

	// Display the rectangle's data.
	double displayData(double length, double width, double area)
	{
		cout << "The rectangle's length is: " << length << endl;
		cout << "The rectangle's width is: " << width << endl;
		cout << "The rectangle's area is: " << area << endl;
		return(length, width, area);
	}

1
2
3
4
5
6
double length, width, area;

cout << getLength();
cout << getWidth();
cout << getArea();
cout << displayData();


Should be :
1
2
3
4
5
6
double length, width, area;

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


Last edited on
SakurasouBusters' code will work, but I'm curious. OP, I don't see anywhere in your code, or in SakurasouBusters' code, where anything is actually passed by reference. Do you understand what that actually means?
I need help

What help do you need? Please be specific.

Your program compiles but has linker errors because your function prototypes do not match your implementations.

Lines 8,9 must match lines 43,51 respectively.

Line 56: You can't return 3 values. See the comma operator here:
http://www.cplusplus.com/doc/tutorial/operators/
Last edited on
Line 56: You can't return 3 values. See the comma operator here.

The OP actually returns one value. Only the value of the last expression after comma (,) is returned, and the OP may not be aware of that.
Topic archived. No new replies allowed.