How do I make my program pause

This is a discussion on How do I make my program pause within the C++ Programming forums, part of the General Programming Boards category; Im writing this program for school...but I'm curious how I would make it pause. I will include the code:: include ...

  1. #1
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36

    How do I make my program pause

    Im writing this program for school...but I'm curious how I would make it pause. I will include the code::

    include <fstream.h>


    int main()
    {
    int max, min, guess;
    char answer;


    cout << "Enter a maxium number : ";
    cin >> max;
    cout << "Enter a minium number : ";
    cin >> min;
    cout <<endl;
    cout <<"Think of a number between your maxium and minium number"<<endl;
    cout <<"This program will guess it"<<endl;
    cout <<endl;
    cout <<"You have 5 seconds before the program will attempt to guess it" <<endl;
    ---I WANT IT TO PAUSE HERE BEFORE IT GOES INTO THE DO----
    do
    {
    guess = (min + max) / 2;

    cout <<" Is this number correct : " << guess <<endl;
    cout <<" If it is please enter Y. " <<endl;
    cin >> answer;
    cout <<endl;

    if ( answer == 'Y' || answer == 'y')
    {
    cout <<"The computer rules " <<endl;
    continue;
    }

    cout <<" If the number was incorrect: "<<endl;
    cout <<" -- Enter an H for higher. "<<endl;
    cout <<" -- Or an L for lower. "<<endl;
    cin >>answer;
    cin.ignore (80, '\n');

    if (answer == 'H' || answer == 'h')
    { min=guess; }
    else
    { max=guess; }

    }

    while ( answer != 'Y' && answer != 'y' );

    return 0;
    }


    THanks alot
    Last edited by quiksilver9531; 01-23-2002 at 06:10 PM.

  2. #2
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    maybe if your compiler adds it.......

    //whatever the code is
    getch();
    //the rest


    getch(); is the code to pause till a key is pressed, you have to include conio.h
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  3. #3
    Señor Member
    Join Date
    Jan 2002
    Posts
    561
    You could add sleep(5000); (I think it's in stdlib). And btw, you forgot to include iostream.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    :: choke ::

    FAQ

    :: cough ::

    search

    :: splutter ::

  5. #5
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    include conio.h

    int wait = getch();
    return 0;
    Monday - what a way to spend a seventh of your life

  6. #6
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36
    Thanks guys...you dont need iostream if you use fstream btw

    thats according to my comp teacher

  7. #7
    Unregistered
    Guest
    #include <stdlib.h>


    system ("Pause");

  8. #8
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    avoid system("") calls if you can - they are poor programming practice, as they are slow, unoptomized, and they are system specific and make porting difficult
    Monday - what a way to spend a seventh of your life

  9. #9
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Your comp science teacher is right. Iostream.h is included in fstream.h because fstream.h derives from it and other headers.

    BTW, listen to Iain, he is correct about system().

  10. #10
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36
    Thanks, The getch( ) worked thanks, didnt try system tho

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 06-17-2008, 12:38 PM
  2. How to make the program not to wait for the function?
    By maxorator in forum C++ Programming
    Replies: 10
    Last Post: 10-02-2005, 04:02 PM
  3. How do you make your program record keystrokes
    By aaroroge in forum C++ Programming
    Replies: 1
    Last Post: 06-25-2005, 07:55 AM
  4. make a program stay....
    By Nirav in forum C Programming
    Replies: 6
    Last Post: 10-12-2003, 08:01 PM
  5. pause program at console
    By datainjector in forum C# Programming
    Replies: 1
    Last Post: 03-27-2003, 12:36 AM

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