Help with passwd verifying program

Hi gays (i'm Artur from Italy), can someone of you help me? I started to study a C++, but i have some question, how can i color a single word for exemple i have a program that verify a passwd, i want to write (Access denien (in italian Accesso negato) using red color)?

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
40
41
42
43
44
45
46
47
48
49
50
51
//Passwd
#include <iostream>
#include <windows.h>

using std::cin;
using std::cout;
using std::endl;



     int main()
{
     system("COLOR 0A");
     
    int pass;
    int Counter=0;
    for(Counter=0; Counter<3; Counter--)
    {

                   cout<<"Inserisci la PASSWORD di sicurezza (solo cifre da 0 a 9)...:\n"<<endl;
    cin>>pass;
    for(int x=0; x<5; x++)
    {
            cout << "\nControllo PASSWORD in corso...";
            _sleep(100);
            Beep(2500, 100);
            }
            if (pass!=12345) 
                             
                             
                             
                            { 
                           cout<<"\a\n\nAccesso negato...\n"<<endl;
                           }
                           else break;
                           }
                           
                           
                        cout<<"\a\n\nAccesso concesso...\n"<<endl;
                        
                           int scelta;
                           cout<<"1) PASSWORD di sicurezza massima:\n"<<endl;
                           cin>>scelta;
                           
                           if (scelta==1) cout<<"PASSWORD di sicurezza massima: 12345\n"<<endl;
                           else cout<<"\a\nPuoi inserire solo il numero 1...\n\a"<<endl;
                           
                           system("pause");
                           return 0;
                           }
Last edited on
Changing the color is not implemented in C++. You have to use an external library or system call to change color of the console window. A library such as ncurses could handle that, but since you are already using system... and I also see that you are using the pause command... I am going to assume you are at a microsoft dos command prompt of some sort. Color changing in this situation can be done using system to execute the dos color command.

http://www.computerhope.com/color.htm
Example: system("color 0C"); //0 - background black //C - foreground light red
Thanks for answer, the problem is this way color all my text, i want to color a single word (example: ACCESS DENIED) in red and (ACCESS GRANTED) in green, only this words ;)
And yes, i start learning c++ two weeks ago, on a windows OS.
Another question, as you can see, in my "program" which i copied and modifyed a bit, a password is 0-9 how can i change it to A-Z?
And, when i insert my passwd, then i chose 1, the program ask to press any button and it close, how can i do to restart a program without re-open it again? Here is some code i think?
Thanks for your help :D
Topic archived. No new replies allowed.