C++ Program ATM MACHINE ARRAY CONFUSION

Discussion in 'C++' started by TBsparky, Feb 13, 2011.

  1. TBsparky

    TBsparky New Member

    Joined:
    Feb 13, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Uni
    Location:
    In a house
    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);
    }
    
     
  2. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    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
     
    shabbir likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice