CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    2

    Font color and inputing a character.

    My name is Mikael aKa LimePatch and I have just started programming in C++ yesterday. I have had previous programming experiance in LUA.
    Im using Code::blocks 8.02 to make a simple program. The program ask for a password and if I enter correct password it says correct password and if I enter wrong password it says access denied.
    What I would like is to change password to a word instead of a number, how do I do that?
    Seccond thing I would like is to chage the font text that appears to be green instead, how do I do that?
    This is my code -->


    #include <iostream>

    using namespace std;

    int main()
    {
    int password; // variable
    cout<<"Welcome to my program! Programmed by Limepatch \n\n\n\n"; // Input message
    cout<<"Please input your password: "; // Input message
    cin>> password; // The input is put in password
    cin.ignore(); // Throw away enter
    if ( password == 7777 ) { // If correct password is entered
    cout<<"Correct password!\n"; // say if correct password.
    }
    else {
    cout<<"Access denied!\n"; // say if wrong password
    }
    cin.get();
    }

  2. #2
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: Font color and inputing a character.

    Quote Originally Posted by LimePatch View Post
    My name is Mikael aKa LimePatch and I have just started programming in C++ yesterday. I have had previous programming experiance in LUA.
    Im using Code::blocks 8.02 to make a simple program. The program ask for a password and if I enter correct password it says correct password and if I enter wrong password it says access denied.
    What I would like is to change password to a word instead of a number, how do I do that?
    Seccond thing I would like is to chage the font text that appears to be green instead, how do I do that?
    This is my code -->


    #include <iostream>

    using namespace std;

    int main()
    {
    int password; // variable
    cout<<"Welcome to my program! Programmed by Limepatch \n\n\n\n"; // Input message
    cout<<"Please input your password: "; // Input message
    cin>> password; // The input is put in password
    cin.ignore(); // Throw away enter
    if ( password == 7777 ) { // If correct password is entered
    cout<<"Correct password!\n"; // say if correct password.
    }
    else {
    cout<<"Access denied!\n"; // say if wrong password
    }
    cin.get();
    }
    You'd change password to a std::string, #including <string> in your source. You'd also change the equality test to if ( password == "thepassword" ).

    To change the colour of the text, try this function.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  3. #3
    Join Date
    Feb 2009
    Posts
    2

    Re: Font color and inputing a character.

    the character password worked great thank you!
    Last edited by LimePatch; February 22nd, 2009 at 12:39 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured