Sometimes when you have given someone bad advice you just gotta hold your hands up and admit it, ignore what I wrote above, I totally misunderstood what you were asking. :)
O.k. I've looked at your code and for the most part it seems good, until:
1 2 3 4 5 6 7 8 9 10 11
|
for(int h=0;h<=5;h++) //for loop to access the first data
{
for(int i=0;i<ACCOUNT-1;i++) //for loop to check the first data with the rest of the data in the array
{
if(accountNum[h] == accountNum[i]) {
cout << "Error! account num already taken" << endl;
doAgain = true;
break;
}
}
}
|
particularly if(accountNum[h] == accountNum[i])
.
I think that you are trying to search through a pre-existing array of account numbers, and you are trying to see if the account number entered already exists.
In which case this is wrong, because
you are searching through the array where you have just stored the account number you are checking for so it
WILL LEAD TO:
"Error! account num already taken"
being displayed (when
h == 0
&&
i == 0
) because your checking the if the
same thing is the same as itself (if you get me).
E.g:
where
h == 0 && i == 0
your code becomes:
if( accountNum[0] == accountNum[0] )
The solution is changing:
cin >> accountNumTerm[count]
, store the given account number in a
separate integer, check this
ONE VALUE against the values stored in the
accountNum
array.
1 2 3 4 5 6 7 8 9 10 11
|
int nGivenAccoutNumber = 0;
//get input from user and validate
for(int i = 0; i < 5; i++)
{
if(nGivenAccountNumber == accountNum[i])
{
//account number already exists so perform the appropriate behavior
}
}
|
Another thing, the way your
do while
loop is structured will cause it to
loop infinitely if the user enters an account number that
already exists in the
accountNum
array.
Your
do while
loop should (
if I have interpreted your code correctly) should really
encompass all the user input (
it should start at line 8), so that the user can respond and correct any error they make.
I think that covers it.
Apologies for the earlier confusion! If you need any more help feel free to ask, and I'll try not to make a pig ears of it next time :D
Hope this help!