#include <iostream>
#include <string>
using namespace std;
int main( )
{
string password_var;
bool validPass;
int Length_Of;
while ( 1 )
{
cout << "Please enter a password.\n " ;
cin >> password_var;
validPass = false ;
Length_Of = password_var.size ( ) ;
if ( Length_Of < 7 )
{
cout << "Passwords must be at least 7 characters long.\n " ;
continue ; // you don't need to go further in the loop.
}
int i = 0 ;
while ( 1 )
{
cout << password_var[ i] ;
if ( ( password_var[ i] >= '0' && password_var[ i] <= '9' )
|| ( password_var[ i] == '$' )
)
{
validPass = true ;
}
else
{
i = i + 1 ;
}
// beware of assignment '=' and comparison '=='
if ( validPass == true || i >= Length_Of)
break ;
}
if ( validPass == true )
{
cout << "Thank you, that is a valid password.\n " ;
} // add the closing brace.
else
{
cout << "Passwords must include a digit or a dollar sign(0-9,$).\n " ;
}
if ( validPass == true )
break ;
}
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCmludCBtYWluKCkKewogICAgc3RyaW5nIHBhc3N3b3JkX3ZhcjsKICAgIGJvb2wgdmFsaWRQYXNzOwogICAgaW50IExlbmd0aF9PZjsKCiAgICAKICAgIHdoaWxlICgxKQogICAgewogICAgICAgIGNvdXQgPDwgIlBsZWFzZSBlbnRlciBhIHBhc3N3b3JkLlxuIjsKICAgICAgICBjaW4gPj4gcGFzc3dvcmRfdmFyOwogICAgICAgIHZhbGlkUGFzcyA9IGZhbHNlOwogICAgICAgIExlbmd0aF9PZiA9IHBhc3N3b3JkX3Zhci5zaXplKCk7CiAgICAgICAgaWYgKExlbmd0aF9PZiA8IDcpCiAgICAgICAgewogICAgICAgICAgICBjb3V0IDw8ICJQYXNzd29yZHMgbXVzdCBiZSBhdCBsZWFzdCA3IGNoYXJhY3RlcnMgbG9uZy5cbiI7CiAgICAgICAgICAgIGNvbnRpbnVlOyAvLyB5b3UgZG9uJ3QgbmVlZCB0byBnbyBmdXJ0aGVyIGluIHRoZSBsb29wLgogICAgICAgIH0KICAgICAgICBpbnQgaSA9IDA7CiAgICAgICAgd2hpbGUgKDEpCiAgICAgICAgewogICAgICAgIAljb3V0IDw8IHBhc3N3b3JkX3ZhcltpXTsKICAgICAgICAgICAgaWYgKCAocGFzc3dvcmRfdmFyW2ldID49ICcwJyYmcGFzc3dvcmRfdmFyW2ldIDw9ICc5JykgCiAgICAgICAgICAgICAgICAgfHwgKHBhc3N3b3JkX3ZhcltpXSA9PSAnJCcpCiAgICAgICAgCQkpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHZhbGlkUGFzcyA9IHRydWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpID0gaSArIDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgLy8gYmV3YXJlIG9mIGFzc2lnbm1lbnQgJz0nIGFuZCBjb21wYXJpc29uICc9PScKICAgICAgICAgICAgaWYgKHZhbGlkUGFzcyA9PSB0cnVlIHx8IGkgPj0gTGVuZ3RoX09mKSAKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICBpZiAodmFsaWRQYXNzID09IHRydWUpCiAgICAgICAgewogICAgICAgICAgICBjb3V0IDw8ICJUaGFuayB5b3UsIHRoYXQgaXMgYSB2YWxpZCBwYXNzd29yZC5cbiI7CiAgICAgICAgfSAvLyBhZGQgdGhlIGNsb3NpbmcgYnJhY2UuCiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgY291dCA8PCAiUGFzc3dvcmRzIG11c3QgaW5jbHVkZSBhIGRpZ2l0IG9yIGEgZG9sbGFyIHNpZ24oMC05LCQpLlxuIjsKICAgICAgICB9CiAgICAgICAgaWYgKHZhbGlkUGFzcyA9PSB0cnVlKQogICAgICAgICAgICBicmVhazsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==