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;
    }

}*/

there is a problem with your search user function. you never initialize i. your call to cin replaces the account number with whatever the user enters. to search for a record you need a for loop to check the number entered by the user against the numbers stored in the array. not sure if this is the function your talking about though.

Your code should look like below if you want to return all balance for an account.

int userInput = 0;
cout<<"Please enter the account number you would like to search"<<endl;
cin>>userInput

// iterate through all accounts to find
for(int i=0; i<10; ++i)
{
     // check if account number found
     if(bank_accounts[i].A_number == userInput)
     {
          cout<<"The current balance is "<<bank_accounts[i].A_balance<<endl;
     }
}

I've updated the code with chiwawa10's code (thanks!) and am now getting this error
main.cpp:137: error: ISO C++ forbids comparison between pointer and integer

any thoughts? there aren't any pointers are there....or is it an issue with the global array?

Hi sorry, fixed that error now, changed the userInput to a char array and used strcmp to search the bank_accounts array for a match.

Thanks for all the help!

Hi Sparkle Jam, no offense but i would just like to give you some advice...firstly start writing STANDARD code. In all probability you are using an antique compiler like turbo c++. Dump that right NOW.
Secondly NEVER USE GOTO. Repeat that a 100 times. It makes code-maintenance so very difficult.
Also, I found you were tying to return from your functions by a call to main(). You should generally never call main() as it's the property of the OS and you shouldn't be interfering.
Hope it helps.
Cheers...

Thanks NP-complete. I'm currently using Netbeans 6.7.1 :S. I'm only using goto in this project I don't tend to make habit of using it. I'll take the return to main out now, I'm fairly new to this sorry!

Thanks for all the advice!
Btw, do I close my own thread, and if so, how?

The omnipresent i variables in your code are uncanny.
What is the purpose of the i parameter in new_user supposed to be, for example?
Or the global one?
Or the uninitialised one (!!) in account_closure?

Great. glad that you liked it.

About closing threads, i don't know...i think its upto the admins and mods...lets see if others can clarify.

>> Btw, do I close my own thread, and if so, how?

Nope, threads stay open at Daniweb. If your question got solved, you can mark it solved by clicking the link "Mark this Thread as Solved".

This question has already been answered. Start a new discussion instead.