Issue: After iterating through a cin password and saving instances of integers in the password to an integer variable(number). I use an if statement to search for conditions: if there are 5 or less numbers in the password AND the password is less than ten characters in length. The statement seems to be evaluating to true when only one of the conditions is true instead of both.
Result I am getting:
Test input not evaluating correctly
Question: Declare a Boolean variable named goodPassword. Use goodPassword to output "Valid" if codeWord contains no more than 5 digits and codeWord's length is less than 10, and "Invalid" otherwise.
My Code
#include <iostream>
using namespace std;
int main() {
string codeWord;
bool goodPassword;
unsigned int i;
int number;
cin >> codeWord;
for (i=0; i<codeWord.size(); ++i){
//check each index for number and declare size limit
if( isdigit(codeWord[i]) ){
i=number;
}
} /* Type your additional code here */
if ((sizeof(number) < 6) && (codeWord.size()<10)){
goodPassword = true;
}
else {
goodPassword=false;
}
if (goodPassword) {
cout << "Valid" << endl;
}
else {
cout << "Invalid" << endl;
}
return 0;
}