Thread: Need help on slowing program down

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    7

    Need help on slowing program down

    Hi all,
    i am a newb @ c++ since i just started this course in september

    i want to ask a question about slowing down a program
    is there like a command to do that??
    i want it to display a "*" that moves left to right
    i have tried alot of stuff and it still didnt work XD
    here is my code that runs uber-fast

    Code:
             int x = 1;
             do{
                   gotoxy(x,1);
                   cout << "*" ;
                   x ++;
                   gotoxy(x - 1,1);
                   cout << "  " ;
                   gotoxy(x,1);
                   cout << "*" ;
                      if( x == 81 ) {
                           x = 1;
                        }
                   } while ( x != 0 );
             system("PAUSE");
             return (0);

  2. #2
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    You might want to try the Sleep() command, which I believe is in the windows.h or conio.c header file :
    Code:
    #include <iostream.h>
    #include <conio.c>
    #include <windows.h>
    
    int main()
    {
             int x = 1;
             do{
                   gotoxy(x,1);
                   cout << "*" ;
                   x ++;
                   Sleep(50);  // This is the only line I touched...
                   gotoxy(x - 1,1);
                   cout << "  " ;
                   gotoxy(x,1);
                   cout << "*" ;
                      if( x == 81 ) {
                           x = 1;
                        }
                   } while ( x != 0 );
             system("PAUSE");
             return (0);
    }

    Sleep() according to MSDN : The Sleep function suspends the execution of the current thread for at least the specified interval.

    Sleep(int x) where x is the number of milliseconds to pause the program.

    Hope this helps,
    Korhedron

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    7
    thanks for the help, Korhedron

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM