Need help with passing variables to functions!

Ok so I'm taking a C++ class right now and we are working with functions. I really don't understand them and my teacher doesn't really "teach". I have problems with passing one value in a function to another function. Like in this program all I'm doing is finding length, width, and area of a rectangle, then showing it again.

I should say beforehand that I am definitely no expert on coding, and please don't give me a hard time about how bad my code may be, I'm just trying to learn!

Thanks.

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
 #include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
	double getLength(double length);
	double getWidth(double width);
	double getArea(double area);
	void displayData(double data);
	getLength();
	getWidth();
	getArea();
	displayData();
	getch();
}

double getLength(double length)
{
	cout<<"Please enter the rectangles length"<<endl;
	cin>>length;
	return length;
}

double getWidth(double width)
{
	cout<<"Please enter the rectangles width"<<endl;
	cin>>width;
	return width;
}

double getArea(double area)
{
	area = length * width;
	return area;
}

void displayData(double area, double length, double width, double data)
{
	cout<<"Length: "<<length<<endl;
	cout<<"Width: "<<width<<endl;
	cout<<"Area: "<<area<<endl;
}
Compare what you do with the example here: http://cplusplus.com/doc/tutorial/functions/

What is different?
Topic archived. No new replies allowed.