Thread: Program closes prematurely. Help needed

  1. #1
    Registered User
    Join Date
    Apr 2006

    Program closes prematurely. Help needed

    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....

    using namespace std;
    class Volume {
                 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;
              cout << "The volume of the cube is: " << cube1.volume();
              return 0;
    Thanks for the help.

  2. #2
    Registered User
    Join Date
    Aug 2003
    try add a cin.ignore() right before cin.get()
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Those FAQs don't help much in this case.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help needed with program - urgent thanks!
    By lildevil in forum C Programming
    Replies: 1
    Last Post: 03-09-2008, 06:45 AM
  2. Drawing program architecture - information needed
    By Marko_D in forum Windows Programming
    Replies: 1
    Last Post: 11-28-2003, 07:46 PM
  3. program closes fast
    By MrSoy in forum C Programming
    Replies: 5
    Last Post: 04-10-2003, 08:00 PM
  4. Program chews up a lot of CPU when it closes
    By bman1176 in forum Windows Programming
    Replies: 4
    Last Post: 01-10-2002, 11:23 AM
  5. Bug favour needed re: C++ Program
    By Nicole in forum C++ Programming
    Replies: 2
    Last Post: 12-05-2001, 07:13 AM