amount transfer function cant work

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include<string>
using namespace std;

//Data Type
typedef struct
{
char account_number[12];
char name[31];
char Address[130];
char phoneNumber[11];
double balance;
}ACCOUNT;

//function call
void list();
void display_acc(ACCOUNT prod[], int acc_amount);
void search(ACCOUNT prod[], int acc_amount);
void withdrawbalance(ACCOUNT prod[], int acc_amount);
void deleteAccount(ACCOUNT prod[], int acc_amount);
void amountTransfer(ACCOUNT prod[], int acc_amount);
int search_acc(ACCOUNT prod[], int acc_amount);

int main()
{
ACCOUNT products[50];
int index = -1,choice,acc_amount;


ifstream inFile("Account.txt");

//Get the amount from the product.txt
if (!inFile)
cout << "Error opening input file\n";
else
{
ACCOUNT products[50];
int index = -1,choice;

inFile.getline(products[++index].account_number, 12);
while (inFile)
{
if (inFile.peek() == '\n')
inFile.ignore(256, '\n');
inFile.getline(products[index].name, 31);
inFile.getline(products[index].Address,130);
inFile.getline(products[index].phoneNumber, 11);
inFile >> products[index].balance;

// read next number
inFile >> products[++index].account_number;
}
inFile.close();

// menu starts
do
{
cout << "================================================================================" << endl;
cout << "\t\t\t\t MAYBANK SERVICE CENTER" << endl;
cout << "================================================================================" << endl;
cout << "Do you want to:\n";
cout << "1. List all accounts\n";
cout << "2. Search for bank accounts\n";
cout << "3. withdraw amount for bank account\n";
cout << "4. Transfer amount\n";
cout << "5. Advanced search \n";
cout << "6. Delete your accounts\n";
cout << "7. Exit\n";
cout << "--------------------------------------------------------------------------------" << endl;
cout << "Enter choice: ";
cin >> choice;

//get the data from the product.txt
switch (choice)
{
case 1: display_acc(products,index);
break;
case 2: search(products, index);
break;
case 3: withdrawbalance(products, index);
break;
case 4:amountTransfer(products, index);
break;
case 6: deleteAccount(products, index);
break;
case 7: break;
default: cout << "Invalid choice\n";
}
} while (choice != 7);

ofstream outFile("Account.txt");
if (!outFile)
cout << "Error opening output file, records are not updated.\n";
else
{
for (int i = 0; i < index; i++)
{
outFile << products[i].account_number<< endl;
outFile << products[i].name << endl;
outFile << products[i].Address << endl;
outFile << products[i].phoneNumber << endl;
outFile << products[i].balance << endl;
}
outFile.close();
}
}
return 0;
}

void list()
{
cout << "================================================================================" << endl;
cout << "\t\t\t\t BANK SERVICE CENTER" << endl;
cout << "================================================================================" << endl;
cout << "Do you want to:\n";
cout << "1. List all accounts\n";
cout << "2. Search bank accounts\n";
cout << "3. Withdraw amount for bank account\n";
cout << "4. Transfer amount for friends and family\n";
cout << "5. Advanced search for display accounts\n";
cout << "6. Delete your accounts\n";
cout << "7. Exit\n";
cout << "--------------------------------------------------------------------------------" << endl;
cout << "Enter choice: ";

}


void search(ACCOUNT prod[], int acc_amount)
{
char search_acc[12];
cout << "Please enter your Account Number ";
fflush(stdin);
cin.getline(search_acc, 12);

if (search_acc[0] == '0' && strlen(search_acc) == 1)
return ;

for (int i = 0; i < acc_amount; i++)
{
if (strcmp(search_acc, prod[i].account_number) == 0)
{
cout << "Account No. :" << prod[i].account_number << "\n";
cout << "Name :" << prod[i].name << "\n";
cout << "Address :" << prod[i].Address << "\n";
cout << "Phone No. :" << prod[i].phoneNumber << "\n";
cout << "Balance :RM" << prod[i].balance << "\n";
return ;
}

}
cout << "Account Number not found.\n";
return ;
}
void withdrawbalance(ACCOUNT prod[], int acc_amount)
{

char account_number[12];
int withdraw_amt;
double withdraw;
cout << "Please enter account number: ";
cin >> account_number;

for (int i = 0; i < acc_amount; i++)
{
if(strcmp(account_number, prod[i].account_number) == 0)
{
cout << "Current balance is: RM" << fixed << setprecision(2) << prod[i].balance;
cout << "\nPlease enter amount of withdraw: RM";
cin >> withdraw_amt;
prod[i].balance = prod[i].balance- withdraw_amt;
cout << "Withdraw success...\n";
cout << "New balance is: RM" << fixed << setprecision(2) << prod[i].balance;
cout << "\n";
return;
}
}

cout << "Number/ID is not found\n";
cout << "\n";
return ;
}




void deleteAccount(ACCOUNT prod[], int acc_amount)
{
char account_number[12];
// display the account has been deleted
cout << "Enter account number that you wish to delete: ";
cin >> account_number;

for (int i = 0; i < acc_amount; i++)
{
if (strcmp(account_number,prod[i].account_number) == 0)
{

cout << " Account Deleted" <<endl;

return ;
}
}
cout << "Please enter correct account number" << endl;
return ;
}

// transfer amount to other client
void amountTransfer(ACCOUNT prod[], int acc_amount)
{
// display amount of client
int index = searchRecord(prod, acc_amount);
int i = searchRecord(prod, acc_amount);
double credit_amounts;
if (index != -1)
{

cout << "The current balance of ID (" << prod[index].account_number << ") is: RM" << prod[index].balance << endl;
}
else
{
cout << "Number/ID is not found\n";
}
if (i != -1)
{
cout << "The current balance of ID (" << prod[index].account_number << ") is: RM" << prod[i].balance << endl;
}
else
{
cout << "Number/ID is not found\n";
}

// display the amount you wish to transfer to
cout << "Please enter the amount you wish to transfer: RM";
cin >> credit_amounts;
prod[index].balance = prod[index].balance - credit_amounts;
prod[i].balance = prod[i].balance + credit_amounts;
cout << "Transfered success...\n";
cout << "The new balance of ID (" << prod[index].account_number << ") is: RM" << prod[index].balance << "\n";
cout << "The new balance of ID (" << prod[i].account_number<< ") is: RM" << prod[i].balance << "\n";
cout << "\n";
return;
}



Sample of txt file

4782684608
Teh Yii Meng
132,Lorong Mahsuri,Taman Bunga Raya,53000 Kuala Lumpur,Selangor
0168745696
8965
6161045859
Alexander Graham
198,Taman Melati,53000 Kuala Lumpur,Selangor
0109536985
563
8546253654
Yew Sii Yang
9G,7 Jalan Mantis,96000 Sibu,Sarawak
0168594793
1285
9856321547
Paramala Bin Dera
78,Jalan Melati,Taman Raya,96500 Bintangor,Sarawak
0138215636
5000
8752326597
Wong Hang Hee
9G,Lorong 5,Jalan Poh Yew,96000 Sibu,Sarawak
0163259645
5627
9536521478
Chen Jen Yang
PJS/9 Jalan Alan,53000 Kuala Lumpur,Selangor
0172583697
479632
9632147855
Diamond Lu Juan Zhi
PJS/15,Jalan Lagoon Selatan,53000 Kuala Lumpur,Selangor
0123456789
98745
9514787536
Kok Shi Chen
15,Lorong 15,Jalan Bahru,53000 Kuala Lumpur,Selangor
0104569218
51
8521369851
Wong Kam Leng
9G,Lorong 7,Jalan Mantis,96000 Sibu,Sarawak
0168594792
7852
2563149851
Hoo Mei Ling
95,Lorong Mahsuri 3,Taman Asia Jaya,53000 Kuala Lumpur,Selangor
0195631147
85620
9632741258
Billy Lim Yi Cheng
A51,Jalan Sultan,80000 Johor Bahru,Johor
0146321596
1658
7852149658
Eric Wong Yui Mee
36,Jalan Palan, 80000 Johor Bahru,Johor
0198136924
7851
9514753625
Lim Chee Ang
6J,Lorong Melati,Taman Negara,56000 Kuala Lumpur,Selangor
0163219852
451
8463152499
Clement Wong Kim Shun
51,Lorong 5,Jalan Lim Kim Hoo,53000 Kuala Lumpur,Selangor
0128821563
6666
7412389514
Abaraham Limcoln
21,Jalan Mahsuri,96500 Bintangor, Sarawak
0169531475
7890
1510965233
Ngu Wen Tang
20,Lane 5,Taman Utara,36300 Sungai Rumun,Perak
0149632587
4035
1254369836
Lee Ka Wei
39,Lane 2,Taman Selatan,36300 Sungai Rumun,Perak
0123698521
965
9854426521
Yew Huo Shenf
A96,Taman Bukit Nanas,36750 Chikus,Perak
0189632145
5854
2354869321
Lam Chee Kun
36,Lane 6,Jalan Emma,39007 Tanah Rata,Pahang
0189634562
965528
9852
Bill Gates
1835,73rd Ave,Medina,Washington,USA
0152369517
25864


























Topic archived. No new replies allowed.