Box dimensions problem

I'm having problems with the DisplayData function in my program. I was wondering why when I put area in the function it says it's undefined, but if I take it away it says there are to few.

My program is not complete 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
#include<iostream>
#include<iomanip>
using namespace std;

double Volume (double length, double width, double height);

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

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



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

	//setprecision

	cout.setf(ios::fixed, ios::floatfield);
	cout.setf(ios::showpoint);
	cout<<setprecision(2);

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


	do//do-while 
	{
		
		BoxDimensions(length, width, height, volume);

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

		//function calls and variables
		if(volume=0);
		{
			volume=width*length*height;
		}
		if(width=0);
		{
			width=volume/(height*length);
		}
		if(length=0);
		{
			length=volume/(height*width);
		}
		if(height=0)
		{
			height=volume/(length*width);
		}
		
		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 
Last edited on
Several issues with this code:
1
2
3
4
    if (volume=0);
    {
        volume=width*length*height;
    }

1. the assignment operator = is used instead of == for testing equality.

2. the first line should not end with a semicolon. That brings the entire if statement to an end, the rest of the code in braces is always executed.

3. it should end with an else as there follow other mutually-exclusive conditions to be tested.

Should look like this:
1
2
3
4
5
    if (volume == 0)
    {
        volume=width*length*height;
    }
    else 


Last edited on
Also I don't see area declared anywhere. As in double area = 1.0;
something like that. Unless i'm missing it.
Last edited on
Um, should you only have 1 function outside of main? This program should be really simple.
chervil, i changed all my if's to else except the first one and removed the semicolons but now it asks for semicolons after the else

Yanson my area is declared inside of my void DisplayData or is this wrong???

Last edited on
There should be an else after every if except the last one.
then it goes like this:
1
2
3
4
5
6
7
8
if (  )
{

}
else if ( )
{

}

repeat lines 5 - 8 as many times as required. This is of course just an outline, you need the details inside the brackets too.

If area is declared inside function DisplayData(), then there's no need for it to be in the parameter list.

Topic archived. No new replies allowed.