The code is a four-character password generator. I have an if/else break system setup, but I can't figure out why it isn't working. The loop generates past the limit until it exhausts all options, which I'm having a hard time properly debugging. I'm very new to anything other than javascript and HTML, so any help would be useful. Thanks!
#include <iostream>
using namespace std;
int
main () {
char char1;
char char2;
char char3;
char char4;
int numPasswordsGenerated = 0;
cout << "Password Generator:" << endl;
/* Generates four-character passwords (excludin digits) by exhausting all character
options between '!' and '~' starting with the fourth character. Once the fourth
character exhausts all options, the third character increases by the next character
in the binary lineup, then continuing with the fourth character. This process continues
until the numPasswordsGenerated integer reaches the desired number, or the password
output becomes "~~~~"; whichever comes first.
*/
char1 = '!';
while (char1 <= '~') {
char2 = '!';
while (char2 <= '~') {
char3 = '!';
while (char3 <= '~') {
char4 = '!';
while (char4 <= '~') {
// cout << char1 << char2 << char3 << char4 << endl;
numPasswordsGenerated++; //!*FIXME*!
cout << numPasswordsGenerated << endl; //DEBUG DELETE
if (numPasswordsGenerated == 10)
break;
char4++;
}
char3++;
}
char2++;
}
char1++;
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire