Thread: The Matrix

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    7

    The Matrix

    Hi, i got bored and decided to make the matrix shower code in C++. However, i don't know how to change text color to green. Can anyone help me? Here is my code so far.

    Code:
    #include <fstream.h>
    #include <stdlib.h>
    #include <conio.h>
    
    void TheMatrix()
    {
                    int a = 0, b = 1, counter = 1, randnum1, randnum2;
    	do
    	{
    		randnum1 = rand();
    		randnum2 = rand();
    		if(randnum1 > randnum2)
    		{
    			cout << a;
    		}
    		else
    		{
    			cout << b;
    		}
    	}while(counter != 2);
    }
    
    main()
    {
    
    	cout << "This is the Matrix" << endl;
    	getch();
    	TheMatrix();
    
    	return 0;
    }
    Hehe, i made The Matrix function just so that i could have a function call entitled "The Matrix".

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    What compiler/os are you using neo?

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    7

    lol

    I am using Microsoft Developer 6.0++.
    I would appreciate any help.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    you'll need to include windows.h for this.
    Code:
    SetConsoleTextAttribute( GetStdHandle(
    			     STD_OUTPUT_HANDLE ),
    			     FOREGROUND_RED );
    FOREGROUND_RED obviously changes the foreground to red, also there others look them up in MSDN if you'd like. When you want to switch back to white do this

    FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN

    Or I defined a constant to use like so...
    const int FOREGROUND_WHITE = 0x000F;
    Last edited by MrWizard; 05-19-2002 at 03:38 PM.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    system("color 3");

    or something like that. I dunno the color nr though so you have to play around with it. This changes all the text to green. The already posted method only changes the afterwards written text. Since you are making a matrix shower you prolly dont need any other colors so this should work fine.

  6. #6
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb textcolor()

    textcolor(GREEN);
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    7

    COol

    Thanks a lot you guys. I will try messing with the background too.

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    7

    Super Fastness

    Hey guys, it works. Thanks ErionD, your solution worked. But my problem now is that the 0's and 1's scroll soooooooo fast that you can't even make out a single character. Is there any way to put a time delay type of thing on it, to slow it down?

  9. #9
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by gabaji123
    Hey guys, it works. Thanks ErionD, your solution worked. But my problem now is that the 0's and 1's scroll soooooooo fast that you can't even make out a single character. Is there any way to put a time delay type of thing on it, to slow it down?
    Look up the sleep() function


    Originally posted by Sorensen
    What compiler/os are you using neo?
    LMFAO!

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    249
    [i]


    LMFAO! [/B]
    What is " LMFAO! , is that an operating system
    C++
    The best

  11. #11
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by NANO


    What is " LMFAO! , is that an operating system
    ROFLMFAO!!!!!!

  12. #12
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    Unhappy And now what is this

    Please forgive me,

    English is my 6 Language. And I am working on both English and PHP at the same time. Actualy you can tell that from the Mistakes that I always make when I write a thread.

    Anyway ... Can you tell me now .... What does it mean.

    ROFLMFAO!!!!!!
    Thanx
    C++
    The best

  13. #13
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Roll on floor...laugh my freaking arse off

  14. #14
    Registered User
    Join Date
    Apr 2002
    Posts
    249

    OK ..

    hmmmmmmmmm.

    Now I know For sure I know
    C++
    The best

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. Gauss-Jordan Matrix Inversion in C++
    By Max_Power82 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2006, 08:31 PM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM