Hi guys, I'm having a few problems with my code.
I run the program and input 10 users for my account system, but when I try to recall the values for any account, I can only call the first balance I entered.
I've been looking at the code, trying to find the error and have come up stumped. Could you please lend me a fresh perspective?
Thank you
#include <stdlib.h>
#include <iostream.h>
#include <float.h>
#include <string.h>
typedef struct Account
{ char AH_fisrtname[15];//account holder first name
char AH_surname[20];//account holder surname
char A_number[4];//account number
char A_type[7];//account type
float A_balance;//account balance
float A_deposit;//deposit
float A_withdrawal;//withdrawal
}Account;
Account bank_accounts[10]={};//array that stores the bank account details
int i;
//------------------------------------------------------------------------------
int new_user(int i, Account bank_accounts[10]);
float search_user(Account bank_accounts[10]);
float transactions(Account bank_accounts[10]);
float account_closure(Account bank_accounts[10]);
float average_amount(Account bank_accounts[10]);
float get_account_details(Account bank_accounts[10]);
float print_account_details(Account bank_accounts[10]);
//------------------------------------------------------------------------------
int main()
{
//------------------------------------------------------------------------------
//*integers/floats/characters below*
char select_option;//menu select option
Make_menu:
cout<<"Welcome to the Banking System"<<endl;
cout<<"MENU"<<endl;//title
cout<<"[0] NEW USER DETAILS"<<endl;
cout<<"[1] Search for account"<<endl;//opens string compare feature
cout<<"[2] Withdrawal or Deposit"<<endl;//input amounts for withdrawal/deposit
cout<<"[3] Close Account"<<endl;//set account balance to zero
cout<<"[4] Exit Application"<<endl;//exit
//cout<<"[5] Average of all accounts on system"<<endl;//average
//cout<<"[6] Input and display last 10 transactions"<<endl;
cout<<endl;
cin>>select_option;
//------------------------------------------------------------------------------
//if statements that call functions
//------------------------------------------------------------------------------
if ( select_option =='0')//add new users
{
new_user(i, bank_accounts);
goto Make_menu;
}
else if(select_option == '1')//search account
{
search_user(bank_accounts);
goto Make_menu;
}
//------------------------------------------------------------------------------
else if(select_option == '2')//deposits and withdrawals
{
transactions(bank_accounts);
goto Make_menu;
}
//------------------------------------------------------------------------------
else if(select_option == '3')//close account
{
account_closure(bank_accounts);
goto Make_menu;
}
//------------------------------------------------------------------------------
else if (select_option == '4')//exit app screen
{
cout<<"Exitting application"<<endl;
return (EXIT_SUCCESS);
}
//------------------------------------------------------------------------------
else if( select_option == '5')
{
//average_amount(bank_accounts);
goto Make_menu;
}
//------------------------------------------------------------------------------
else if( select_option =='6')
{
//get_account_details(bank_accounts);
//print_account_details(bank_accounts);
goto Make_menu;
}
//------------------------------------------------------------------------------
else//loop menu
{
cout<<"This was not a requested operation"<<endl;
goto Make_menu;
}
}
int new_user(int i, Account bank_accounts[10])
{
bank_accounts[i].A_balance = 0;
for(i=0;i<10;i++)//this will be 10 once it's fixed
{
cout<<"Please enter a 4 digit account number"<<endl;
cin>>bank_accounts[i].A_number;
cin.ignore();
cout<<"Please enter the customer's first name"<<endl;
cin>>bank_accounts[i].AH_fisrtname;
cin.ignore();
cout<<"Please enter the customer's surname"<<endl;
cin>>bank_accounts[i].AH_surname;
cin.ignore();
cout<<"Please enter the account type - Debit/Savers"<<endl;
cin>>bank_accounts[i].A_type;
cin.ignore();
cout<<"Please enter opening balance"<<endl;
cin>>bank_accounts[i].A_balance;
cin.ignore();
}
return bank_accounts[i].A_balance;
}
float search_user(Account bank_accounts[10])
{
int i;
cout<<"Please enter the account number you would like to search"<<endl;
cin>>bank_accounts[i].A_number;
cout<<"The current balance is "<<bank_accounts[i].A_balance<<endl;
return main();
}
float transactions(Account bank_accounts[10])
{
int i;
float new_bal_dep;
float new_bal_with;
char with_cont;
char dep_cont;
char trans_cont;
//------------------------------------------------------------------------------
cout<<"Please enter the customer's 4 digit account number"<<endl;
cin>>bank_accounts[i].A_number;
cout<<"This is the current balance "<<bank_accounts[i].A_balance<<endl;
cout<<"Would you like to make a withdrawal or deposit?"<<endl;
cin>>trans_cont;
if(trans_cont == 'w')
{
do{
cout<<"Please enter the amount you would like to withdraw"<<endl;
cin>>bank_accounts[i].A_withdrawal;
if(bank_accounts[i].A_withdrawal>bank_accounts[i].A_balance)
{
cout<<"There is not sufficient funds in the acocunt"<<endl;
}
else
{
new_bal_with = bank_accounts[i].A_balance - bank_accounts[i].A_withdrawal;
cout<<"The new balance of the account is "<<new_bal_with<<"."<<endl;
}
cout<<"Would you like to make another withdrawal?"<<endl;
cin>>with_cont;
} while ( with_cont == 'y');
return bank_accounts[i].A_balance == new_bal_with;
}
else if(trans_cont == 'd')
{
do{
cout<<"Please enter the amount you would like to deposit"<<endl;
cin>>bank_accounts[i].A_deposit;
new_bal_dep = bank_accounts[i].A_balance + bank_accounts[i].A_deposit;
cout<<"The new balance of the account is "<<new_bal_dep<<"."<<endl;
cout<<"Would you like to make another deposit?"<<endl;
cin>>dep_cont;
} while ( with_cont == 'y');
return bank_accounts[i].A_balance == new_bal_dep;
}
else
{
cout<<"This was not a requested operation!"<<endl;
return main();
}
}
float account_closure(Account bank_accounts[10])
{
int i;
cout<<"Enter account number you would like to close"<<endl;
cin>>bank_accounts[i].A_number;
bank_accounts[i].A_balance = 0;
cout<<"The account balance has been set back to zero"<<endl;
return main();
}
/*float get_account_details(Account bank_accounts[10])
{
int i;
float b;
for(i=0;i<10;i++)
{
cout<<"Please input the cutomer's account number"<<endl;
cin>>bank_accounts[i].A_number;
for(b=0;b<10;b++)
{
cout<<"Input the transaction amount"<<endl;
cin>>bank_accounts[i].A_balance[b];
}
}
}
float print_account_details(Account bank_accounts[10])
{
int i;
float b;
for(i=0;i<10;i++)
{
cout<<bank_accounts[i].A_number<<endl;
for(b=0;b<10;b++)
{
cout<<bank_accounts[i].A_balance[b]<<endl;
}
}
}
float average_amount(Account bank_accounts[10])
{
float average,a,c;
for(int i=0;i<10;i++)
{
for (a=0;a<10;a++)
{
c =bank_accounts[i].A_balance[a];
}
average=c/10;
cout<<average<<endl;
}
}*/