void check_valid_password()
{
char string[16];
bool loop = true;
do{
loop = true;
cout << "Enter the password you would like to use,\n"
<< "it must conain atleast 5 letters, start with\n"
<< "a letter, contain atleast one capital letter\n"
<< "and have no punctuation.";
cin.getline (string,16);
if (strlen(string) < 5)
{
loop = false;
cout << "Your password is too short! Must be atlest 5 characters.";
}
}
while (loop = false);
system("pause");
}
DOH... stupid me... you can do it however you want it is part of your own style. I enjoy while loops vs dowhile loops... 1 less line. but they all have uses.
Here is your problem.. you are going to hate me...
while (loop == false);
hah gl have fun
your while statement sets loop equal to false. and thus defeating any logic operators. your loop will go forever if you didnt have user input.
lol i looked at this code a few times before i saw that... it all looked good to me then i remembered to double check logic operators. so obvious yet so hidden... heh sneaky gotta love code... or you'l go crazy
#include <string>
#include <iostream>
usingnamespace std;
bool kill;
int main()
{
string pass;
while (kill == false)
{
cout << "Enter the password you would like to use,\n"
<< "it must conain atleast 5 letters, start with\n"
<< "a letter, contain atleast one capital letter\n"
<< "and have no punctuation.\n";
getline (cin,pass);
if (pass.length() >= 5 && pass.length() <= 16)
{
kill = true;
}
elseif (pass.length() < 5)
{
cout << "Your password is too short! Must be atlest 5 characters.";
}
else
cout << "Your Passwork is too long. Please make it shorter.";
}
}
oh remember to add \n in choice locations to give your function a pretty factor. ;)
No problem. i find that just looking at more code makes be a better programmer. The more lines i look at, the better i am. And it always gives me the question... How would i do that?