ADD CODE ERROR ,Reference-parameters

I ' m a beginner...
Can anyone help me too find out what's wrong with my code and fix it. thanks very much.

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
88
89
90
91
92
#include <iostream>
using namespace std;


// Function prototypes:


void GetValues(double &, double &);

float ComputeArea(double, double);

void PrintArea(double);


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

   cout << "This program computes the area of a rectangle." << endl;
   cout << "You will be prompted to enter both the length and width.";
   cout << endl << "Enter a real number (such as 7.88 or 6.3) for each.";
   cout << endl << "The program will then compute and print the area.";
   cout << endl;
   GetValues(length,width);
   ComputeArea (length,width);
   PrintArea(area);


   return 0;
   }


/* 
   Purpose:  To ask the user for the length and width of a rectangle and
             to return these values via the two parameters.
   Return:   Length   The length entered by the user.
             Width    The width entered by the user.
*/

void GetValues(double & l, double & w)
   {
	   l = length;
	   w = width;
	   cout << " Enter the length: " ;
	   cin>> l;
		   cout << "enter the width: ";
	   cin>>w;

    // add code to get Length and Width

return  GetValues() ;
   }


/* Given:  Length   The length of the rectangle.
           Width    The width of the rectangle.
   Purpose:   To compute the area of this rectangle.
   Return: The area in the function name.
*/

double ComputeArea(doulbe l, double W)

   {
	 int area; 
	 l = length;
	 W = width;
     area = l * W ;     


return area; 

	// add code to compute area 

   }



/* Given:  Area    The area of a rectangle.
   Purpose:   To print Area.
   Return: Nothing.
*/
void PrintArea(double a)
   {
	   a = area;
	    l = length;
	    W = width;
	   cout << "The area of the "  << length  << " by "
         << width  << " rectangle is "  << area  << endl;

	// add code to print area of the rectangle
   }
Firstly, lines 43, 43 (the same with 65, 66 and 84, 85, 86). 'length' and 'width' are in different scope, so you cannot access them from other functions. Though I don't see, why would you want to, since you pass them as parameters. Remove those lines.
Secondly, in line 51, return GetValues() ; is a recursive call which will prevent you from returning to main. This function is void, so you don't need to return anything. Remove that line as well.
Finaly, function PrintArea here takes only one parameter, but is suposed to print three. Make it void PrintArea(double a, double l, double w);
Thank you very much!!- hamsterman

very helpful...
Topic archived. No new replies allowed.