I get segmentation when I run the program. Please help me figure out why. I've posted the two chunks of code that should include the problem. Thanks! Let me know if you need to see more coding.
. . .
do
{
menu();
cout<<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
int pos=linearSearch(acno, acNums, numAccs);
if(acno.length()!=10)
cout<<"Account number must be ten digits."<<endl;
if(pos>0)
cout<<acno<<" cannot be assigned to multiple customers."<<endl;
else
{
cout<<"Enter the first name>"<<endl;
cin>>fName;
cout<<"Enter the last name>"<<endl;
cin>>lName;
cout<<"Enter middle initial>"<<endl;
cin>>midInit;
cout<<"Enter initial deposit>"<<endl;
cin>>initBal;
}
if(initBal < 25.00)
cout<<"Insufficient funds to open account."<<endl;
else
openAccount(acno,fName,lName,midInit,initBal,acNums,fNames,lNames,
midInitials,balances,numAccs);
}
break;
case 2:
{
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
if(acno.length()!=10)
cout<<"Account number must be ten digits."<<endl;
else if(linearSearch(acno,acNums,numAccs)<0)
cout<<"Account number does not exist"<<endl;
else
closeAccount(acno,acNums,fNames,lNames,
midInitials,balances,numAccs);
}
break;
case 3:
{
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
if(acno.length()!=10)
cout<<"Account number must be ten digits."<<endl;
else if(numAccs<0)
cout<<"Account number does not exist"<<endl;
else
{
cout<<"Enter deposit amount>"<<endl;
cin>>amount;
}
if(amount<=0.00)
cout<<"Amount must be at least $0.01."<<endl;
else
deposit(acno,amount,acNums,balances,numAccs);
}
break;
case 4:
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
if(acno.length()!=10)
cout<<"Account number must be ten digits.";
else if(numAccs<0)
cout<<"Account number does not exist"<<endl;
else
{
cout<<"Enter withdrawal amount>"<<endl;
cin>>amount;
}
if(amount<=0.00)
cout<<"Amount must be at least $0.01."<<endl;
else
withdraw(acno, amount, acNums,balances,numAccs);
break;
case 5:
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
if(acno.length()!=10)
cout<<"Account number must be ten digits."<<endl;
else if(numAccs<0)
cout<<"Account number does not exist"<<endl;
else
inquiry(acno,acNums,fNames,lNames,midInitials,balances,numAccs);
break;
case 6:
customersList(acNums,fNames,lNames,balances,numAccs);
break;
case 0:
exit(1);
break;
default:
cout<<"Enter a valid choice."<<endl;
break;
}
do
{
menu();
cout<<"Enter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
int pos=linearSearch(acno, acNums, numAccs);
if(acno.length()!=10)
cout<<"Account number must be ten digits."<<endl;
if(pos>0)
cout<<acno<<" cannot be assigned to multiple customers."<<endl;
else
{
cout<<"Enter the first name>"<<endl;
cin>>fName;
cout<<"Enter the last name>"<<endl;
cin>>lName;
cout<<"Enter middle initial>"<<endl;
cin>>midInit;
cout<<"Enter initial deposit>"<<endl;
cin>>initBal;
}
if(initBal < 25.00)
cout<<"Insufficient funds to open account."<<endl;
else
openAccount(acno,fName,lName,midInit,initBal,acNums,fNames,lNames,
midInitials,balances,numAccs);
}
break;
case 2:
{
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
if(acno.length()!=10)
cout<<"Account number must be ten digits."<<endl;
else if(linearSearch(acno,acNums,numAccs)<0)
cout<<"Account number does not exist"<<endl;
else
closeAccount(acno,acNums,fNames,lNames,
midInitials,balances,numAccs);
}
break;
case 3:
{
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
if(acno.length()!=10)
cout<<"Account number must be ten digits."<<endl;
else if(numAccs<0)
cout<<"Account number does not exist"<<endl;
else
{
cout<<"Enter deposit amount>"<<endl;
cin>>amount;
}
if(amount<=0.00)
cout<<"Amount must be at least $0.01."<<endl;
else
deposit(acno,amount,acNums,balances,numAccs);
}
break;
case 4:
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
if(acno.length()!=10)
cout<<"Account number must be ten digits.";
else if(numAccs<0)
cout<<"Account number does not exist"<<endl;
else
{
cout<<"Enter withdrawal amount>"<<endl;
cin>>amount;
}
if(amount<=0.00)
cout<<"Amount must be at least $0.01."<<endl;
else
withdraw(acno, amount, acNums,balances,numAccs);
break;
case 5:
cout<<"Enter a ten digit account number>"<<endl;
cin>>acno;
if(acno.length()!=10)
cout<<"Account number must be ten digits."<<endl;
else if(numAccs<0)
cout<<"Account number does not exist"<<endl;
else
inquiry(acno,acNums,fNames,lNames,midInitials,balances,numAccs);
break;
case 6:
customersList(acNums,fNames,lNames,balances,numAccs);
break;
case 0:
exit(1);
break;
default:
cout<<"Enter a valid choice."<<endl;
break;
}