Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   C++ Program ATM MACHINE ARRAY CONFUSION (http://www.go4expert.com/forums/cpp-program-atm-machine-array-confusion-t24962/)

TBsparky 14Feb2011 04:58

C++ Program ATM MACHINE ARRAY CONFUSION
 
Hey everyone I'm a little confused with my C++ ATM Machine program. My program, at the moment needs the user to enter 10 accounts before he can operate it, however i've tried pre setting the code for 10 details in an array but i cannot do it. Hopefully Someone can help me.

Code:

#include <cstdlib>
#include <iostream>
#include <string.h>

using namespace std;



typedef struct account_details
{
    char firstname[10];
    char lastname[10];
    int accountnumber;
    float balance;
    int pnumber;
    char accountstatus[9];
} account_details;

void dataloading(account_details accountdet[]);
int askselectioninput();
void deposit_amount(account_details accountdet[]);
void withdraw_amount(account_details accountdet[]);
void cancel_acc(account_details accountdet[]);
void display_acc(account_details accountdet[]);
void logout(account_details accountdet[]);

int main(){
    cout<<"========================================="<<endl;
    cout<<"========================================="<<endl;
    cout<<"||    WELCOME TO THE ENCLAVE G-E-C-K    ||"<<endl;
    cout<<"========================================="<<endl;
    cout<<"========================================="<<endl;

    account_details accounts [10]; //the struct of account_details for the array accounts
    int option =0; //for the option selection
    //accounts[0].accountstatus * == {'Act'};
    accounts[0].balance = 1000; //makes the account 0's balance = 1000
    dataloading(accounts);
    while (true){

        option = askselectioninput();

        if (option ==1)
        {

            deposit_amount(accounts);
        }   

        else if (option ==2)
        {

            withdraw_amount(accounts);
        }

        else if (option ==3)
        {

        display_acc(accounts);
        }

        else if (option ==4)
        {
        cancel_acc(accounts);
        }
        else if (option ==5){
            logout (accounts);
        }

    }
}

int askselectioninput(){
    int option= 0;

    cout<<"==============YOUR TRANSACTION CHOICES==================="<<endl;
    cout<<"Press 1 for Deposit                  Press 2 for Withdraw"<<endl;
    cout<<"press 3 for Display Balance          Press 4 for Close the account"<<endl;
    cout<<"===============Press 5 for Quit=========================="<<endl;
    cin>>option;
    if (option >0 && option <6){
        return option;
    }

    else {
        cout<<"--Incorrect Value--"<<endl<<endl;
        return askselectioninput();
    }

}

void dataloading(account_details accountdet[]){
    int number;
    int i;
    for (i=0;i<2;i++)
    {
    cout<<"Enter your First Name: "<<endl;
    cin>>accountdet [i].firstname;
    cout<<"Enter your Last Name:"<<endl;
    cin>>accountdet [i].lastname;
    cout<<"Please enter your Pin: "<<endl;
    cin>>accountdet [i].pnumber;
    cout<<"Now please enter your Account Number: (0-9) "<<endl;
    cin>>accountdet [i].accountnumber;
    }
    cout<<"Please Enter your account number for verification: "<<endl;
    cin>>number;
       
    cout<<"||==============x=============||"<<endl;
    cout<<"||    LOGGED INTO GECK:    ||"<<endl;
    cout<<"||===========================||"<<endl;
    cout<<"-------------------------------------------"<<endl;
    cout<<"Welcome MR/MRS/Miss/Master: "<<accountdet [number].lastname<<endl;
    cout<<"Your current Balance is: "<<accountdet [number].balance<<endl;
    cout<<"Your Account number is: "<<accountdet [number].accountnumber<<endl;
    cout<<"-------------------------------------------"<<endl;

}


void display_acc(account_details accountdet[])
{
    int number;
    number = (accountdet[number].accountnumber);
cout<<"=========================================================="<<endl;
cout<<"------------------ USER DETAILS -------------------      "<<endl;
cout<<"Welcome: "<<accountdet [number].firstname<<accountdet [number].lastname<<endl<<endl;
cout<<"Your current Balance is: "<<accountdet [number].balance<<endl;
cout<<"Your Account number is: "<<accountdet [number].accountnumber<<endl;
cout<<"Your Account Status is: "<<accountdet [number].accountstatus<<endl;

if (accountdet[number].balance <0)
{
cout<<"====YOU HAVE BECOME OVERDRAWN!===="<<endl;
}
cout<<"============================================================"<<endl<<endl;
}

void withdraw_amount(account_details accountdet[])
{
        int number;
    number = (accountdet[number].accountnumber);
    float amount;
cout<<"--------------------------------------------------"<<endl;
cout<<"--        Withdraw from G-E-C-K                --"<<endl; //Function that executes if F is chosen
cout<<"--------------------------------------------------"<<endl;
cout<<"Please Enter your amount to withdraw: "<<endl;
cin>>amount;
    accountdet[number].balance = accountdet[number].balance + amount;
}



void cancel_acc(account_details accountdet[])
{
    int number;
    number = (accountdet[number].accountnumber);
    char firstname;
    char lastname;
cout<<"=========================================================="<<endl;
cout<<"            CLOSING THIS ACCOUNT:                          "<<endl;
//accountdet[0].firstname;
//lastname = accountdet[0].lastname;
//lastname = 'N/A';
//firstname  = 'N/A';

cout<<accountdet[number].firstname;
cout<<accountdet[number].lastname;
cout<<"============================================================"<<endl<<endl;

}

void deposit_amount(account_details accountdet[])
{
        int number;
    number = (accountdet[number].accountnumber);
    float amount;
    cout<<"--------------------------------------------------"<<endl;
    cout<<"--        Deposit into G-E-C-K                --"<<endl; //Function that executes if F is chosen
    cout<<"--------------------------------------------------"<<endl;
        cout<<"Please Enter your amount to deposit: "<<endl;
        cin>>amount;
    accountdet[number].balance = accountdet[number].balance - amount;
}

void logout (account_details accountdet[])
{
cout<<"==========================="<<endl;
cout<<" YOU ARE NOW LOGGED OUT"<<endl;
cout<<"==========================="<<endl<<endl;
    dataloading(accountdet);
}


jimblumberg 14Feb2011 10:14

Re: C++ Program ATM MACHINE ARRAY CONFUSION
 
First you have several problems in your code:

Code:

void display_acc(account_details accountdet[])
{
    int number;
    number = (accountdet[number].accountnumber);

In the above snippet you are using number before you initialize it. You are doing this several places in your code.

Jim


All times are GMT +5.5. The time now is 18:40.