bool isValid(int actual_PW[], int entered_PW[], int random_Nums[])
{
bool valid = false;
//*****************************This is where i'm having trouble**********************************
for (int index = 0; (!valid) && (index < sizeof(actual_PW)); index++)
{
random_Nums[index] = actual_PW[index];
if (entered_PW[index] != )
{
valid = false;
}
}
return valid;
}
#1) If you are trying to compare the password entered (entered_PW[]) with the actual password (actual_PW[]), why is random_Nums[] needed to check validity?
#2) What is the purpose of random_Nums[index] = actual_PW[index]; ?
#3) What is the obvious comparison for entered_PW[index] in the IF ?
#4) If you only set valid to FALSE, how can it return TRUE?
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37
the obvious would be to compare the entered_PW to the actual_PW but looking back over the rest of the code i think i forgot to assign each digit in the actual_PW to the random 1-3. how could i do this? or is
actual_PW[index] = random_Nums[index];
sufficient?
That's seems to be exactly what the function is for, so yes.
in this iteration it couldn't return true, and that is mostly because i hadnt fully figured out what i needed to compare to get the true.
heres an update on that function
bool isValid(int actual_PW[], int entered_PW[], int random_Nums[])
{
bool valid = false;
//*****************************This is where i'm having trouble**********************************
for (int index = 0; (!valid) && (index < sizeof(actual_PW)); index++)
{
actual_PW[index] = random_Nums[index];
if (entered_PW[index] == actual_PW[index])
{
valid = true;
}
else
valid = false;
}
return valid;
}
Your thinking is backwards. If any values are TRUE, this function returns TRUE.
When creating a function that returns an all-or-nothing comparison, like this function, it's best to start by setting the response to 'all' (TRUE). Then during the the testing, if any value fails, a single FALSE comparison sets the result to FALSE.
The way you have it, the result assumes FALSE. Then during the the testing, if any value succeeds, that single TRUE comparison sets the result to TRUE. Clearly not what you want.
Think of this as an ANDing function. Any fail returns FALSE, All successes return TRUE. Yours is an ORing function.
But to make matters worse, because of the ELSE clause, the only comparison that matters is the very last. You will return T/F based on that comparison alone.
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37
Question Answered as of 1 Year Ago by
WaltP