Function Problem

I'm having trouble displaying my final function which displays my results. I am all out of ideas and 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
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
#include<iostream>
#include<iomanip>
using namespace std;

void DisplayData (double length, double width, double height, double volume, double area);

void BoxDimensions (double length, double width, double height, double volume);



int main()
{
	//variable declaration
	double width, length, height, volume;
	char repeat='y';

	//user instructions
	cout<<"This program will accept four inputs."<<endl;
	cout<<"For the measurement you would like too find, "<<endl;
	cout<<"please enter 0."<<endl<<endl;


	do//do-while 
	{

		//intro input
		cout<<"Please enter the width of your box: ";
		cin>>width;
		cout<<"Please enter the length of your box: ";
		cin>>length;
		cout<<"Please enter the height of your box: ";
		cin>>height;
		cout<<"Please enter the volume of your box: ";
		cin>>volume;

			//rerun the program
		cout<<"Enter y or Y to rerun the program, anything else to quit ";
		cin>>repeat;
	}while (repeat=='y'||repeat=='Y');//end do-while

}//end main

void BoxDimensions(double length, double width, double height, double volume)

{
//function calls and variables
		if(volume==0)
		{
			volume=width*length*height;
		}
		else if(width==0)
			{
				width=volume/(height*length);
			}
		else if(length==0)
				{
					length=volume/(height*width);
				}
		else if(height==0)
					{
						height=volume/(length*width);
}//end BoxDimensions

void DisplayData(double length, double width, double height, double area, double volume)
{
	//set precision
	cout.setf(ios::fixed, ios::floatfield);
	cout.setf(ios::showpoint);
	cout<<setprecision(2);

	cout<<"The width of your box is "<<setw(21)<<width<<endl;
	cout<<"The length of your box is "<<setw(20)<<length<<endl;
	cout<<"The height of your box is "<<setw(20)<<height<<endl;
	cout<<"The volume of your box is "<<setw(20)<<volume<<endl;
	cout<<"The area of your box is "<<setw(22)<<area<<endl;
	return DisplayData;
}//end Displaydata 
You may want to pass your variables by reference in your BoxDimensions() function if you want the changes to be seen outside that function. By passing your variables by value (the current mode) you send copies of these variables into the function and any changes are lost when the function returns.

void BoxDimensions(double &length, double &width, double &height, double &volume)
Also you can keep those variables in pre-defined structure, and then returning it.

Ps. you are missing closing bracer in BoxDimensions... not mentioning return DisplayData; in void function
So if I change line 43 to what you have it should transfer the values I have entered?
You may want to study the following tutorials:

http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/functions2/

But other than changing the function signature you don't need to change anything else, other than fixing any other errors with your code.
Im totally not answering the question, but one thing, you'd better use a convention (some call it ascii), it does like that:

cout << *space* "lol" << *space* endl;
so cout << "lol" << endl;

instead of sticking words together. Sorry once again for being off topic :-"
Topic archived. No new replies allowed.