How can i slow this down?

Im jus playin around with this code, its supposed to give off the matrix effect ex. the running random symbols and numbers b4 the movie starts. So i kinda did it a generic way, but i want to know is there a way to slow down the letters, or the whole program? (and yes, it is supposed to be on an ifinite loop.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
using namespace std;

int main()
{
    int entermatrix;
    
    cout << " Press 1 to enter the matrix 0.0 " << endl;
    cin >> entermatrix;
    switch (entermatrix){
           case 1:
                do
                {
                         cout << "A B   D   F   H   J   L   N   P   R   T U   W   Y  " << endl;
                         cout << "!   # $   ^ & * ( ) _   - = , . ; '   | ? 0 1   0 1" << endl;
                         cout << "a   c   e   g   i   k   m   o   q   s t   v   x   z" << endl;
                         cout << "1 2 3 4 5 6 7 8 9 0 0 1 2 3 4 5 6 7 8 9 0 1 0 1 1 0" << endl;
                         cout << "0 1   1 0 0   0 1 1 0   1 0 0 0 0 1   1 1 0 1 1   0" << endl;
                         cout << "1 0 0 0   1 1 0   0 1 1 0 1   1 0 0 0 0 0   0   1 1" << endl;
                         cout << "0 0 0 0   1 0 0 0 1   0 1 0 0 0 0   1 0 1 0 1 1 0 0" << endl;
                         
                         
                         }while(entermatrix==1);
                         
                         
                         
                         case 0:
                              
                              cout << "later" << endl;
                              break;
                              system("pause");
                              return 0;
                              }
                              }
Last edited on
Use a delay function.

On Windows, #include <windows.h> and use VOID WINAPI Sleep( DWORD dwMilliseconds );
A millisecond is 1 000 = 1 second.

On POSIX systems, #include <unistd.h> and use void usleep( unsigned long microsec ); (BSD version. The SuSE version conforms to this one in use.)
A microsecond is 1 000 000 = 1 second.

Hope this helps.
Didnt work for me for some reason, the letters are still moving just as fast and the program doesnt seem slower by any means.
Last edited on
use the thing you used to slow it down inside the do { } while loop.
I did, maybe i have the format wrong.

VOID WINAPI Sleep( DWORD dwMilliseconds );
Last edited on
This doesn't work?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <windows.h>

int main()
  {
  int letter = 'A';
  HANDLE hstdin = GetStdHandle( STD_INPUT_HANDLE );

  std::cout << "Press any key to quit\n";

  while (WaitForSingleObject( hstdin, 0 ) != WAIT_OBJECT_0)
    {
    std::cout.put( letter );
    if (++letter > 'Z') letter = 'A';
    Sleep( 50 );
    }
  FlushConsoleInputBuffer( hstdin );

  return 0;
  }
That just compiles to a program that flashes and goes away. i took out return 0 but i dont know what else would make it close but ill say no.
There is something wrong with your development environment if it just flashes and disappears. That program will not terminate until you press a key.

[edit] To see if your IDE is simply pre-loading the input buffer, you can stick a copy of line 17 on line 8 and see if it still flashes.
Last edited on
That essentially would be awsome, but i need a mix of symbols, letters and those letters and symbols scrolling in a downward fashion(or looking like it) with some parts broken to make the "effect"

In the program i made, everything is moving so fast that you cant tell what its supposed to be. so i wanted to slow it down so that the text itself (all text) is moving slower. not uber slow but slowly. theres only one good version of this that i found done in C# and i wanted to do it in C++

http://www.mediafire.com/?sharekey=f192bddc1e0676cdd2db6fb9a8902bda
^ not the one i downloaded, in fact he uses a pre-made font to do it, but covers essentially wat i want to try and do
Try adding a delay function at the end of the do using time.h or something, just make it hold for a second after all the couts. You shouldn't have to change your code that way.
Last edited on
Hello again, i found a solution to my problem. Duoas, you were right about the sleep cmd but you should post how to use it correctly. no void or dword needs to be used:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<iostream>
#include<windows.h>

using namespace std;

int main()
{
    int entermatrix;
    
    cout << " Press 1 to enter the matrix 0.0 " << endl;
    cin >> entermatrix;
    
    switch (entermatrix){
           case 1:
                do
                {
                         
                         Sleep(2);
                         cout << "A B   D   F   H   J   L   N   P   R   T U   W   Y  " << endl;
                         cout << "!   # $   ^ & * ( ) _   - = , . ; '   | ? 0 1   0 1" << endl;
                         cout << "a   c   e   g   i   k   m   o   q   s t   v   x   z" << endl;
                         cout << "1 2 3 4 5 6 7 8 9 0 0 1 2 3 4 5 6 7 8 9 0 1 0 1 1 0" << endl;
                         cout << "0 1   1 0 0   0 1 1 0   1 0 0 0 0 1   1 1 0 1 1   0" << endl;
                         cout << "1 0 0 0   1 1 0   0 1 1 0 1   1 0 0 0 0 0   0   1 1" << endl;
                         cout << "0 0 0 0   1 0 0 0 1   0 1 0 0 0 0   1 0 1 0 1 1 0 0" << endl;
                         
                         
                         }while(entermatrix==1);
                         
                         
                         
                         case 0:
                              
                              cout << "later" << endl;
                              break;
                              system("pause");
                              return 0;
                              }
                              }

I got it slowed to where i want it now so rock on and thank you all!!
Last edited on
Glad you got it working.

But you should know, I am not obligated to post anything. What you got are function prototypes pulled right off of MSDN and the Linux man pages. You can expect to see such things when people answer questions, so you should learn to recognize them, not complain about how cut'n'pasting them didn't work. (Sorry. I just read what I wrote and it sounds a lot harsher than I meant it to be. Notice how I don't retract it though.)


In C and C++, all functions have a prototype, AKA a type, just like variables and constants and other data. A functions type is: what kind of thing it returns, and what kinds of things (and in what order) it takes as arguments. The compiler must know this information for you to use functions (well, to use them properly, at least). And the programmer usually needs to know it also.
Topic archived. No new replies allowed.