I'm a beginner in C++, so this might be considered an elementary problem, but bare with me. The program is just supposed to create a class that's used to compute the volume of a cube. It asks for the three dimensions, but then closes. Here's the code....
Thanks for the help.Code:using namespace std; class Volume { public: int x, y, z; void set_dimensions(){ int a, b, c; cout << "Enter the length: "; cin >> a; cout << endl << "Enter the width: "; cin >> b; cout << endl << "Enter the height: "; cin >> c; cout << endl; x = a; y = b; z = c; } int volume() {return (x*y*z); } }; int main(){ Volume cube1; cube1.set_dimensions(); cout << "The volume of the cube is: " << cube1.volume(); cin.get(); return 0; }



LinkBack URL
About LinkBacks


