Thread: pausing

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    16

    pausing

    i am trying to make my menu system pause so that users can read the screen before the menu system loops back up.

    Code:
    int main(int i){
    int x;
    x=1;
    do
    {
    	
    	book dbase;
    	savei savey;
    	dbase.open(i);
    }
    	while(x=1);
    
    return(0);
    
    };
    this is the loop that main is in,

    Code:
    choice=getchar();
    choice=toupper(choice);
    switch(choice) {
    
    	case 'A': {
    		cout<<"You selected find a book\n";
    		
    		cout<<" Please enter the name of the book";
    		
    		break;}
    		
    	case 'B': {
    		cout<<"You selected find an Author\n";
    		break;}
    		
    	case 'C': {
    		cout<<"You selected find a publisher\n";
    		break;}	   
    		
    	case 'D': {
    		cout<<"You selected to find a Year\n";
    		break;}
    	
    	case 'E': {
    		cout<<"You selected To find books with CDROMS\n";
    		break;}
    this is part of the case selection for the menu system.

    Im sure there is a very simple function to pause it for a small amount of time, but i cant see it! i have tried a few home made methods but they dont work.


    Any help would be gratefully recived

    Thanks

    Black_Solitare

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    eh, main shouldn't be in a loop...

    generally, to put a pause in a program, you just use cin.get() if you want the user to continue the program flow, or use a timing function if you want control... a sample timer function would be:
    Code:
    void Wait(time_t seconds)
    {
         seconds*=1000;
         time_t begin=time();
         time_t end=time();
    
         while(end-begin<seconds)
              end=time();
    }
    that eats up your processor time though...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    16
    Sadly mine needs to be in a loop or the menu system gives me 2 fingers.

    tried the timer, but ive just noticed what i missed out!

    thanks!

    BS

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    what does your code look like?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    19
    what about Sleep() ?

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    non-portable, but if you have a compiler that supports it and don't plan on porting your code to other operating enviromnents, it's better than my code because it actually puts the thread into a sleep mode... mine just keeps the processor busy until time runs out...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >non-portable
    Anything non-trivial will be. The key is to isolate the non-portable aspects to make porting easier. For example, you could wrap the non-portable sleep function in its own function and header:
    Code:
    #ifndef NONPORTABLE_H
    
    #include <windows.h>
    
    void time_delay(int time);
    
    #endif
    Code:
    #include "nonportable.h"
    
    void
    time_delay(
      int time /* Time to delay */
      )
    {
      Sleep(time);
    }
    Then the rest of the program can be riddled with calls to time_delay without effecting portability. The function can even be inlined for speedier calls.
    My best code is written with the delete key.

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    that's the way I clear the screen...


    /runs from Prelude
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pausing script to read output
    By a_priebe47 in forum C Programming
    Replies: 1
    Last Post: 06-15-2004, 10:16 PM
  2. pausing functions..
    By bluehead in forum C++ Programming
    Replies: 3
    Last Post: 01-13-2002, 03:27 AM
  3. Functions and pausing
    By dv916 in forum C++ Programming
    Replies: 4
    Last Post: 12-28-2001, 05:43 PM
  4. MS DOS not pausing while waiting for imput.
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-14-2001, 09:06 PM
  5. pausing the system
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 10-18-2001, 12:34 PM