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

so you mean i have nothing except using getch() command ?

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.

let me try ...

Thanks a lot nightcrew .:) it works efficently :X

No problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.