my code is being compiled but the window auto close after it execute value. I can do this by using getch() also but i wanto to do it without getch() .please help.

#include <iostream.h>
       #include <stdio.h>

         class greatest{
             private:
               int x,y,z;

             public:
               void getdata();
               void display();
               int largest();

                       };

         int greatest::largest(){
         		int T;
               if(x>y)
               T=x;
               else
               T=y;
               if(T>z)
               return(T);
               else
               return(z);

         }

         void greatest::getdata(){

         	cout << " Enter the value of x, y and z ";
            cin >> x >> y >> z ;


         };

          void greatest::display(){

          	cout << "The greatest value is " <<  largest() ;

          };

        int main(void){

          greatest A;

          A.getdata();
          A.display();
return 0;

          }

You can't. If your compiler supports it then you can have a pause when it is ran through the compiler but no program runs and pauses at the end without being forced to.

I think i had used return 0; to force compiler to be pause. Why its not workng

return 0 has nothing to do with pausing the program, its just a value that gets returned to the program that called it (since main is just a function that returns an int).

Yep. Unless you are on windows then you can use system("PAUSE"); but thats kind of frowned upon.

Try inserting this just before you return zero:

cin.get();
cin.ignore();

Should hold the window open until you press the enter key.

This question has already been answered. Start a new discussion instead.