volume of a box code

I need a sample of a statement to find the volume of a box where V=abc. Would this work.

1
2
3
4
5
6
7
8
9
10
11
12
  Put the code you need help with here.   int L,W,H,volume;

L=10;
W=10;
H=10;
cout << "Give me the volume of a box. \n";
cout << L << endl;
cout << W << endl;
cout << H << endl;
volume = L*W*H;

cout << "Volume =" << volume << endl;



just to add a note I'm a beginning student in a C++ course so I'm just learning data type, functions, operators etc...
Last edited on
Yes, it will work just fine...
But, if you want the user to input sizes for the box like the length, you should use cin

For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;

int main()
{
	int L, W, H, volume;

	cout << "What's the length?" << endl;
	cin >> L;
	cout << "What's the width?" << endl;
	cin >> W;
	cout << "What's the heigth?" << endl;
	cin >> H;

	volume = L*W*H;

	cout << "The Volume is: " << volume << endl;

	return 0;
}


But your code will work fine if you have your sizes already determined..
Remember to use >> instead of << when using cin.
Topic archived. No new replies allowed.