compare the sizes of two boxes

I am trying to compare the sizes of two boxes. I am not sure I am going about this the right way but I don't know how to enter the parameters for the function call in line 28:
//cout << "The biggest box is: " << larger();
Any ideas?

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
 #include <iostream>
struct box
{
	char maker[40];
	float height;
	float width;
	float length;
	float volume;
};
void inputbox(box & input);
float set_volume(box & sample);
char larger(float t1, float t2);
using namespace std;
const int maxlength = 2;
int main()
{
	box * boxpointer = new box[maxlength];
	for (int x = 0; x < 2; x++)
	{
	inputbox(boxpointer[x]);
	}
	delete[]boxpointer;
	//cout << "The biggest box is: " << larger();
	return 0;
}
void inputbox(box & input)
{
	cout << "Enter box details." << endl;
	cout << "Enter box maker: ";
	cin >> input.maker;
	cout << "Enter box height: ";
	cin >> input.height;
	cout << "Enter box length: ";
	cin >> input.length;
	cout << "Enter box width: ";
	cin >> input.width;
	cout << "Volume of box " << input.maker << " is: " << set_volume(input)
		<< endl;
}
float set_volume(box & sample)
{
	sample.volume = sample.height * sample.width * sample.length;
	return sample.volume;
}
char larger(float t1, float t2)
{
	return t1 < t2 ? t1 : t2;
}
Last edited on
What is larger meant to tell you? The size of the larger, or which is larger?
Last edited on
Hello, my aim is to output the maker name of the largest box. So for example if you input a and b as the maker names of the two boxes, and a has a volume of 8 and b has a volume of 12 then I want the output to be:
The biggest box is: b
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
#include <iostream>

struct box {
    char maker[40];
    double height;
    double width;
    double length;
    double volume;
};

void inputbox(box & input);
double set_volume(box & sample);

const int MAXLENGTH = 2;

int main()
{
    box * boxpointer = new box[MAXLENGTH];
    box largest;
    for (int x = 0; x < MAXLENGTH; x++) {
        inputbox(boxpointer[x]);
        if(largest.volume < boxpointer[x].volume) {
            largest = boxpointer[x];
        }
    }
    std::cout << "The biggest box is: " << largest.maker;
    delete[] boxpointer;
    return 0;
}

void inputbox(box & input)
{
    std::cout << "Enter box details.\n"
                 "Enter box maker: ";
    std::cin >> input.maker;
    std::cout << "Enter box height: ";
    std::cin >> input.height;
    std::cout << "Enter box length: ";
    std::cin >> input.length;
    std::cout << "Enter box width: ";
    std::cin >> input.width;
    input.volume = set_volume(input);
    std::cout << "Volume of box " << input.maker << " is: " 
              << input.volume << '\n';
}

double set_volume(box & sample)
{
    return sample.height * sample.width * sample.length;
}

Topic archived. No new replies allowed.