Thread: Check this code for pausing program

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    3

    Check this code for pausing program

    Hi!

    I'm using this code for a program I got from the tutorials here:

    #include <iostream.h>
    int main() //Most important part of the program!
    {
    int age; //Need a variable...
    cout<<"Please input your age: "; //Asks for age
    cin>>age; //The input is put in age
    if(age<40) //If the age is less than 100
    {
    cout<<"You are pretty young dude!"; //Just to show it works
    }
    else if(age==40) //I use else just to show an example
    {
    cout<<"You are old"; //Just to show you it works...
    }
    else
    {
    cout<<"You are really old"; //Executed if no other statement is executed
    }
    return 0;
    }



    What would I add to make it pause the program?

    Thanks!!

    Jordan

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    Have you read the Board FAQ? Click on "programming FAQ" at the bottom of the screen
    Last edited by Crossbow; 03-21-2002 at 07:42 PM.

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    system("pause");

    You must #include <stdlib.h> or <windows.h> if I'm not mistaken

  4. #4
    Unregistered
    Guest
    use Sleep( int milliseconds ) found in <windows.h>.
    Dead simple

  5. #5
    Registered User GreenCherry's Avatar
    Join Date
    Mar 2002
    Posts
    65
    It doesn't get much simpler than that.

  6. #6
    Registered User heljy's Avatar
    Join Date
    Mar 2002
    Posts
    36
    I had this question before too, and I have read the FAQs.

    However, kbhit(), and getch() are not ANSI compatible.

    I would want my code to work on both Unix ans Windows.

    Anyway to do that?

    will system("pause") work for both unix and windows? (going to try it out later).
    If only life is as easy as C...

  7. #7
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    I don't remember there being a pause program/command for UNIX. Remember that system() is essentially an interface with the command line. EDIT: I am not saying that system() will not work with UNIX (it will work b/c it is ANSI standard) but the problem lies in the fact that there is no pause program/command that you could send to the UNIX shell that will pause the program.

    There is a function for UNIX programming that is called pause() (in unistd.h). If you checked environment variables and did conditional compiler directives (#ifndef, ifdef, etc.) then you could include unistd.h in a UNIX environment and conio.h/windows.h for a windows environment.

    Good luck

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Suggestions for my Check Book program
    By Nor in forum C++ Programming
    Replies: 2
    Last Post: 11-17-2008, 06:44 PM
  2. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  3. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  4. How to make a program that prints it's own source code???
    By chottachatri in forum C++ Programming
    Replies: 38
    Last Post: 03-28-2008, 07:06 PM
  5. how do I morse code converting program
    By panfilero in forum C Programming
    Replies: 17
    Last Post: 10-29-2005, 09:16 PM