Hello all,
I am working on an assignement for school and is just about finished however I have one problem left to tackle (or only one I have found anyway).
We have to write a very limited billing program for a cable company that stores data in arrays and we are to use functions for every menu procedure.
Anyway my problem is my switch statements I think. We are supposed to prevent the user from accidently overwriting an exisiting account. when the user inputs an account number to add (0-9) if it is assigned an account type of anything other than "3" the program assumes it is an exisiting account and asks the user if they wish to overwrite or select anopther account number. Overwriting the file works fine, however if the user selects no I call the function again to restart the procedure of collecting account information, this seems to happen, however once you complete the account information and the account is setup it starts over one more time and you have to do the process again so it lets you exit that portion of the program. I have been looking at the code for sometime and am not sure what I did wrong. Any assistance would be helpful.
This is the function that is causing me trouble
Code:
int addAcct()
{
//declare local variables
int i = 0;
int acctNUM = 10;
int acctTYPE = 2;
int acctPREM;
char overWrite;
int rerun = 0;
//loops the add acount menu until a valid account number is chosen
while (acctNUM > 9){
system ("cls");
printf("\n\n Cable Dude's Account Management \n\n");
printf(" ** Add Account ** \n\n");
printf(" Please select an account number 0 - 9 \n");
printf("\n Please make a selection and press <Enter> ");
scanf("%d", &acctNUM);
//checks to see if the account already exists and give the option to overwrite the data
if (cableAcct[acctNUM][0] != 3){
printf("\n\n ** Account %d already exists, overwirte? (y/n) **\n",acctNUM);
getchar();
overWrite = getchar();
//checks input to see if the user chose overwrite or not
switch (overWrite){
case 'y' :
break;
case 'Y' :
break;
case 'n' :
rerun = addAcct();
break;
case 'N' :
rerun = addAcct();
break;
}
}
continue;}
//loops until a valid account type is chosen
while (acctTYPE > 1) {
system ("cls");
printf("\n\n Cable Dude's Account Management \n\n");
printf(" ** Add Account ** \n\n");
printf(" Please select an account type \n");
printf(" 0 - Residential \n");
printf(" 1 - Commercial \n");
printf("\n Please make a selection and press <Enter> ");
scanf("%d", &acctTYPE);
continue;}
//clears the previous screen and displays the premium channel selection
system ("cls");
printf("\n\n Cable Dude's Account Management \n\n");
printf(" ** Add Account ** \n\n");
printf(" Please enter the amount of premium channels \n");
printf("\n Please make a selection and press <Enter> ");
scanf("%d", &acctPREM);
//asigns the temporay local variable to the correct array location
cableAcct[acctNUM][0] = acctTYPE;
cableAcct[acctNUM][1] = acctPREM;
printf("\n\n Account successfully added press any key to continue ");
getchar();
getchar();
return 0;
tia
clearrtc