Program closes prematurely. Help needed

This is a discussion on Program closes prematurely. Help needed within the C++ Programming forums, part of the General Programming Boards category; I'm a beginner in C++, so this might be considered an elementary problem, but bare with me. The program is ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    1

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

    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;
              }
    Thanks for the help.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,197
    try add a cin.ignore() right before cin.get()

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    dwk

    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: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    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, 06: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, 10:23 AM
  5. Bug favour needed re: C++ Program
    By Nicole in forum C++ Programming
    Replies: 2
    Last Post: 12-05-2001, 06:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21