What I'm trying to accomplish is for the program to ask the user for their username and password and display it to the screen like this "John, abc123" after the function passwordCheck has confirmed that the password is not less then 5 characters. If the password is less then 5 characters long it keeps asking until its satisfied. The entire program keeps looping until the user enters 0 for username. Here is what I have.

Wow..... I would suggest you start by deciding where you want your inputs to occur. You have the password input occurring in 2 conflicting locations. You also have multiple occurrences of input for username. However, this is okay, the locations you have them in are complementary rather than conflicting.

Depending on what the assignment's instructions are, you may want to consider changing the return of passwordCheck to bool instead. You would then check the length of the string and return true or false depending on the results. You would then use this bool return value to control a validation loop in main().

Teacher wants me to change to a string function and use only one return with no bool. how to?

// function to check whether or not a password is valid
// has no spaces, doesn't use all digits
// is greater then 4 characters in length

bool CheckPassword(string password)
{
     bool valid=false;
     if(password.length()<5)
     return false;
     else
     for(int i = 0; i < password.length(); i++)
     if ((password[i]  >='A') && (password[i] <= 'Z') || (password[i]  >='a') && (password[i] <= 'z'))
     valid=true;
     for(int i = 0; i < password.length(); i++)
     if(password[i]==' ')
     return false;
     
     if(valid)
     return true;
     else
     return false;
 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.