int checkingNum(checking numbers[], int accNum) {
int i = 0; char input; double money = 0.0; int years = 0;
numbers[i].setAcct(accNum);
cout << "Enter s (set balance)" << endl;//method for each letter
cout << "Enter d (display account info)" << endl;
cout << "Enter i(enter number of years for interest )" << endl;
cout << "Enter q(quit processing this account)" << endl;
cin >> input;
while (input != 'q') {
if (input == 's') {
cin >> money;
try {
if (money < 700) {
throw money;
}
}
catch (double money) {
cout << "Error balance must be greater than 700. Re Enter " << endl;
cin >> money;
}
numbers[i].setBalance(money);
if (input == 'q') {
cout << "Account# : ";
cin >> accNum;
if (accNum == 0) {
return 0;//takes me back to beginning of method..and i want to go to main WHY?? confused
}
//else
//pickAcctNum(accNum);
}
i++;
}
You see line 10? A cursory inspection of the compound statement governed by the while condition tells us that input does not change anywhere inside the loop (which is odd for the sole variable in a loop condition, isn't it?) So, if the loop can only be entered if input is not equal to 'q' then the condition on line 25, which is inside the loop, cannot be true. And if that condition cannot be true, then line 29 cannot be reached.
int i = 0; char input; double money = 0.0; int years = 0;
numbers[i].setAcct(accNum);
cout << "Enter s (set balance)" << endl;//method for each letter
cout << "Enter d (display account info)" << endl;
cout << "Enter i(enter number of years for interest )" << endl;
cout << "Enter q(quit processing this account)" << endl;
cin >> input;
while (input != 'q') {
if (input == 's') {
cin >> money;
try {
if (money < 700) {
throw money;
}
}
catch (double money) {
cout << "Error balance must be greater than 700. Re Enter " << endl;
cin >> money;
}
numbers[i].setBalance(money);
cout << "Enter s (set balance)" << endl;//method for each letter
cout << "Enter d (display account info)" << endl;
cout << "Enter i(enter number of years for interest )" << endl;
cout << "Enter q(quit processing this account)" << endl;
cin >> input;
}
cout << "Account# : ";
cin >> accNum;
if (accNum == 0) {
return 0;//takes me back to beginning of method..and i want to go to main
}
//else
//pickAcctNum(accNum);
i++;
return 0;
What makes you think it takes you back to the beginning of the method? If that line is reached control is returned to the calling function. If the calling function is main, it returns to main. If it was some other function or method, it will return to that function or method.
As I mentioned in my previous post, the only way the loop is entered is if the accNum fed to the function is non-zero. It does return if accNum is 0.
It follows, then, that if the loop is being entered into, then the function is not being fed 0, so the perceived problem is probably at the point the function is being called, not within the function.