-
February 21st, 2009, 09:06 PM
#1
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();
}
-
February 21st, 2009, 09:48 PM
#2
Re: Font color and inputing a character.
Originally Posted by LimePatch
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.
-
February 21st, 2009, 09:53 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|