Hello MacRumors!
I'm a new member but a long time lurker, this forum is really great for just about everything.
I seem to be having a problem with my code for c++ using xcode.
Basically, the searchfunction returns a value of i which determines the location of the customer record in the stuct of arrays.
If the function finds the person, it will return a value of >= 0. Otherwise, it will return -1. I believe that works as intended, but what doesnt work is when I prompt the user for a deposit amount. Everything works fine, until a user inputs a letter or string.
Basically, my error checking is not working, my code goes into an infite loop.
Any help is appreciated.
I'm a new member but a long time lurker, this forum is really great for just about everything.
I seem to be having a problem with my code for c++ using xcode.
Basically, the searchfunction returns a value of i which determines the location of the customer record in the stuct of arrays.
If the function finds the person, it will return a value of >= 0. Otherwise, it will return -1. I believe that works as intended, but what doesnt work is when I prompt the user for a deposit amount. Everything works fine, until a user inputs a letter or string.
Basically, my error checking is not working, my code goes into an infite loop.
Any help is appreciated.
Code:
i=searchfunction(bank, total);
if (i != -1 && i >= 0)
{
cout <<endl <<left <<setw(5) <<"" << "Customer Information found\n" <<endl;
cout <<left <<setw(5) <<"" << "name" << setw(24) <<right <<"" <<"Accunt Number" << setw(11) <<"" <<"balance" <<endl <<endl;
cout <<setw(5) <<"" <<setw(28) <<left <<fixed << bank[i].fullname;
cout <<setw(5) <<right << bank[i].acct<<setw(15) <<"$" <<setw(8) <<setprecision(2)<< bank[i].bal <<endl <<endl;
do{
cout <<endl <<left <<setw(5) <<"" << "Enter amount to deposit: $" ;
cin >> amount;
cin.ignore();
if (amount > 0)
{
bank[i].bal = (bank[i].bal + amount);
cout <<endl <<left <<setw(5) <<"" << "New Balance: $" << bank[i].bal <<endl;
updateInput(bank, total, fileName); // updates the customer file that was loaded in
backMenu(bank, size, total, target2, target, fileName); // back to main menu
}
else if(!cin)
{
cout <<endl <<left <<setw(5) <<"" << "Try again, Must be an integer number"<<endl;
cin.clear();
//backMenu(bank, size, total, target2, target, fileName); // back to main menu
}
else
{
cout <<endl <<setw(5) <<"" <<"Minimum Deposit has to be greater than $0\n"<<endl;
//backMenu(bank, size, total, target2, target, fileName); // back to main menu
}
}while(!cin || amount <= 0);
else
{ cout <<"customer not found" <<endl;
backMenu(bank, size, total, target2, target, fileName); // back to main menu