The program is not complete but I have run into a problem in my function which creates a password of upper and lowercase letters.
As far as I can tell the function works properly until the for loop where the password is assembled from the constituent letters. It handles the different letters correctly until it runs out of one or the other type of of characters being used.
I need some help developing the logic which will fill the password vector correctly.
Here is my source code:
void lowerAndUpperCase(int length)
{//generates a password of lower and upper case letters
//length is user entered in the getData function
char upperCase, lowerCase; //holds the random character of each case
int numberCaps, numberLower; //the total number of upper/lowercase letters to be generated
int counterUpper, counterLower; //counter which will count up to the number of upper/lowercase letters
int randInt; //random number to determine whether an upper or lowercase letter is next
vector <char> password; //holds the resulting password
counterUpper = 0; //used in the for loop where the password is assembled
counterLower = 0;
srand(time(NULL)); //seeds the pseudo-random generator
numberCaps = rand() % length + 1; //initial number of capital letters
//If the number of capital letters is too small, program will calculate a new number
while(length > 2 && numberCaps < 2)
numberCaps = rand() % length + 1;
while(numberCaps >= ((2*length)/3))
numberCaps = rand() % length + 1;
while(numberCaps <= (length/3))
numberCaps = rand() % length + 1;
numberLower = length - numberCaps; //number of lowercase letters is totally dependent on numberCaps
int upperSize;
upperSize = numberCaps;
int *capsArray = new int [upperSize];
//array to hold the uppercase letters
int lowerSize;
lowerSize = numberLower;
int *lowerArray = new int [lowerSize];
//array to hold the lowercase letters
for(int i=0; i < numberCaps; i++)
{//generates uppercase letters
upperCase = rand() % 25 + 65;
capsArray[i] = upperCase;
}
for(int j=0; j <= numberLower; j++)
{//generates lowercase letters
lowerCase = rand() % 25 +97;
lowerArray[j] = lowerCase;
}
for(int z=0; z < length; z++)
{//assembles password vector
//ERROR IN HERE SOMEWHERE
randInt = rand() % 10+1;
if(randInt <= 5 && counterLower <= numberLower)
password.push_back (lowerArray[counterLower]);
else if(randInt >= 6 && counterUpper <= numberCaps )
password.push_back (capsArray[counterUpper]);
if(counterUpper > numberCaps)
password.push_back(lowerArray[counterLower]);
else if(counterLower > numberLower)
password.push_back(capsArray[counterUpper]);
counterUpper ++;
counterLower ++;
}
cout<<"Your password is: ";
for(int q=0; q < length; q++)
cout<<password[q];
cout<<endl<<endl;
}
Any help would be greatly appreciated.

New Topic/Question
Reply




MultiQuote





|