Sum/Average Volume Program

I'm a beginner, how would I make it so that I can have someone input the length, width and height for all 3 boxes and then have it output the sum and average volume? Here's an example of what I would like:
INPUT - Enter Box 1 (Length, Width, Height): 10.1 11.2 3.3
INPUT – Enter Box 2 (Length, Width, Height): 5.5 6.6 7.7
INPUT – Enter Box 3 (Length, Width, Height): 4.0 5.0 8.0
OUTPUT – The sum of the volume is 812.806
OUTPUT – The average volume is 270.935

Here's my original code:

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
    
#include <iostream>  
using namespace std;  
  
double box(double length, double width, double height); // use double data  
  
int main()  
{  
    int i, j, k;
	int l, m, n;
	int p, q, r;
	double sum;  

  cout << "Enter Box 1(Length, Width, Height): ";
  cin >> i >> j >> k;
  cout << "Enter Box 2(Length, Width, Height): ";
  cin >> l >> m >> n;
  cout << "Enter Box 3(Length, Width, Height): ";
  cin >> p >> q >> r;
  
  cout << "The sum of the volumes is " << i+j+k+l+m+n+p+q+r << "\n";  
  cout << "The average volume is " << i+j+k+l+m+n+p+q+r / 3.0 << "\n";  
  
  return 0;  
}  
  
// This version of box uses double data.  
double box(double length, double width, double height)  
{  
  return length * width * height ;  
}
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
#include <iostream>

using namespace std;

int main()
{
	double arr[3][3];
	double sum = 1, arrsum = 0;
	char* x[3] = { "Length", "Width", "Height" };

	for (int i = 0; i<3; ++i)
	{
		cout << "Enter Box " << i + 1 << "(Length, Width, Height): \n";
		for (int j = 0; j<3; ++j)
		{
			cout << x[j] << ": ";
			cin >> arr[i][j];
			sum *= arr[i][j];
		}
		arrsum += sum;
		sum = 1;
	}
	cout << "Total: " << arrsum << endl
		<< "Avg: " << arrsum / 3 << endl;
	cin.get(); cin.get();
}
Last edited on
Topic archived. No new replies allowed.