Need help on loops

Please help me on having the following requirements

If the user uses an incorrect format, an error message prints. The user is asked to retype in their password.

The user is asked to retype the same password to verify the selection. If the user types in the wrong password, an error message prints. The user is asked to try again.

As the user types in their password, the letters are hidden with a special character.

I got it to work at where the program allows the user to input their password again after they put it in with the wrong requirements, but this only works once. Also, I have no idea how to hide the inputs with special character.

int main()
{
string yourName, Password; //decalring variables
const int Blue = 11, Yellow = 14, Red = 12, Pink = 13, White = 15, Burgandy = 5, Green = 10, LightGrey = 7, Cyan = 3, LightBlue = 9;
int i = 0, capitolLetter = 0, numbers = 0, total;




cout << "Welcome to my program !!\n";

cout << "Please type in your name: ";
getline(cin, yourName);

printMyTitle(yourName);
changeColor(10);
cout << "Hello, " << yourName;
cout << endl;
cout << "At the next prompt, please type in a password using the guidlines below.\n" << "Your password must start with a capitol letter. \n" << "Your password must end with a digit from 0 to 9.\n" << "Your password must include a special character following the capitol letter.\n";


cout << "type in your password ---->> ";
cin >> Password;




while (Password[0] >= 65 && Password[0] <= 90);

{ changeColor(12);
cout << "Error: Please use a capitol letter. \n";
changeColor(7);
cout << "Please type in your password ---->>";
cin >> Password;

i++; }

while (Password[4] >= 48 && Password[4] <= 57);
{ changeColor(12);
cout << "Error: Please end password with digit. \n";
changeColor(7);
cout << "Please type in your password ---->>";
cin >> Password;
i++; }

while (Password[1] >= 33 & Password[1] <= 47 || Password[1] == 64);
{changeColor(12);
cout << "Error: Please use a special character following your capitol letter. \n" << endl;
changeColor(7);
cout << "Please type in your password ---->>";
cin >> Password;
i++;}



cout << "your password is: " << Password;
cout << endl;
1
2
3
4
5
bool is_valid_password(string password);

do{
   cin >> password;
}while(not is_valid_password(password));


> Also, I have no idea how to hide the inputs with special character.
¿what library are you using for `changeColor()'? they may provide a way to turn off echo.
@ne555

Sorry but I'm not sure what bool does, can you elaborate on where I have to add those codes to? Also, for the changeColor it is a function that my teacher provided me and it's outside of my int main, I'm not sure what you mean by what library? (namespace std?)
bool is a data type, it may hold the values true or false
the function returns true if the password is valid, so you continue with the rest of the code, or returns false if invalid, so you can ask again.

without using functions, you may put a flag in your code, something like
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
int main() {
  string yourName, Password; // decalring variables
  const int Blue = 11, Yellow = 14, Red = 12, Pink = 13, White = 15,
            Burgandy = 5, Green = 10, LightGrey = 7, Cyan = 3, LightBlue = 9;
  int i = 0, capitolLetter = 0, numbers = 0, total;

  cout << "Welcome to my program !!\n";

  cout << "Please type in your name: ";
  getline(cin, yourName);

  printMyTitle(yourName);
  changeColor(10);
  cout << "Hello, " << yourName;
  cout << endl;
  cout << "At the next prompt, please type in a password using the guidlines "
          "below.\n"
       << "Your password must start with a capitol letter. \n"
       << "Your password must end with a digit from 0 to 9.\n"
       << "Your password must include a special character following the "
          "capitol letter.\n";

  bool valid;
  do {
    valid = true;
    cout << "type in your password ---->> ";
    cin >> Password;

    if (not isupper(Password[0]))
      valid = false;
    if (not isdigit(Password[4]))
      valid = false;
    //...
  } while (not valid);
  // here the password is valid
  cout << "your password is: " << Password;
  cout << endl;
}
> Also, for the changeColor it is a function that my teacher provided me and
> it's outside of my int main, I'm not sure what you mean by what library?
> (namespace std?)
there is no functions in the c++ standard to change the font size, the color, turn off echo, etc.
your teacher's give you changeColor(), ¿didn't also give you echo_off(), echo_on(), or something like that?
Topic archived. No new replies allowed.