Function calling problem

I have been working on this program, and for some reason I cannot connect my BoxDimensions function to my DisplayData function. What would need to be done and how would I to that because I am all out of resources. I'm thinking i should have used a function call but i don't know how to do it properly.

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
#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;

		DisplayData (length, width, height, area, volume);
		BoxDimensions (length, width, height, 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)

{
//start if-else
		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 else if


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(20)<<area<<endl;
	
	
}//end Displaydata 
 
void BoxDimensions(double &length, double &width, double &height, double &volume)

Dont use address of these variable. Just remove &.

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

A semicolon after function definition?
Last edited on
I removed the & and that solved some of the problems. Also added a } after the final else-if. Still wont link the 2 functions though
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
#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, area;
	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;
		BoxDimensions (length, width, height, volume);
		DisplayData (length, width, height, volume, area);
			//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
	return 0;
}//end main

void BoxDimensions(double length, double width, double height, double volume)
{
//start if-else
		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 else if
		else
			cout<<"\n";
}

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(20)<<area<<endl;
}//end Displaydata  


Is it your desired result?
Yes it was thank you very much
I thought the intention of the function BoxDimensions was to calculate the missing value (whichever was input with a value of zero).

In order to achieve that, the parameters must be passed by reference (using &).

There are a couple of other flaws. The parameters are passed according to their position. The function DisplayData has its parameters listed in a different order in the call at line 36 and the definition at line 67.

Also area is not initialised, though I think possibly calculation of the area is still to be done. In the meantime, I would set it to zero.

See this tutorial for how to pass parameters by reference:
http://www.cplusplus.com/doc/tutorial/functions2/
Topic archived. No new replies allowed.