Just a HINT

This is a discussion on Just a HINT within the C++ Programming forums, part of the General Programming Boards category; I just want a hint. Im learning arrays in combination with functions i doing a bank program that can track ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    5

    Just a HINT

    I just want a hint. Im learning arrays in combination with functions i doing a bank program that can track of certain amount of account (100). Can someone get me started on the Array. I think i have the functions worked out pretty good but need a hint on how incorporate the array for the accounts

    [code]
    #include <iostream>

    using std::cout;
    using std::cin;
    using std::endl;



    int menu();
    int accountnumber();

    void balancefunction (float); //fuction for Balance
    float depositfunction(float); //function for deposit
    float withdrawalfunction(float);//function for withdrawal
    int main() //main function
    {

    int accountnumber();
    float balance=0;
    int s;
    int account;

    const int customernumber[50];

    account= accountnumber();



    s=menu(); //calling function

    while(s!=5) //condition leading into my switch
    {

    switch (s)

    {
    case 1:

    balance=depositfunction (balance);
    break;

    case 2:
    balance=withdrawalfunction(balance);
    break;
    case 3:
    balancefunction(balance);
    break;
    case 4:
    account=accountnumber();
    break;
    }

    cout<<"Your new balance is: "<<balance<<endl;


    s=menu(); //calling function again to repeat the menu

    }
    cout<<"Good Bye"<<endl;
    return 0;

    }
    int menu() //function
    {
    int x; //declaring varable
    cout<<endl;
    cout<<"*****Welcome to the ATM Services*****"<<endl;
    cout<<endl;
    cout<<"Please select 1-4: "<<endl;
    cout<<"______________"<<endl;
    cout<<" Menu "<<endl;
    cout<<"______________"<<endl;
    cout<<endl;
    cout<<"1. Deposit Money"<<endl;
    cout<<"2. Withdrawal Money"<<endl;
    cout<<"3. Balance"<<endl;
    cout<<"4. New Account number"<<endl;
    cout<<"5. Quit"<<endl;
    cout<<endl;
    cin>>x;

    while ((x!=1)&&(x!=2)&&(x!=3)&&(x!=4)&&(x!=5))
    {
    cout<<"Error Selection must be 1-4"<<endl;
    cout<<"Please Try again"<<endl;
    cin>>x;
    }

    return x;

    }

    void balancefunction(float balance)
    {
    cout<<"The balance is: "<<balance<<endl;//balance

    }



    float depositfunction(float balance)
    {

    float d;
    cout<<"How much would you like to deposit: "<<endl;
    cin>>d;//user input
    balance=balance+d;//formula
    balancefunction(balance);//calling the balance function


    return balance
    }

    float withdrawalfunction(float balance)//withdrawal fuction, returning the value balance

    {
    float w;
    cout<<"How much would you like to ithdrawal: "<<endl;
    cin>>w;

    balancefunction(balance);
    if (balance-w<0)
    cout<<"Sorry, not enough Funds in account"<<endl;
    balance=balance-25;
    }



    else//condition is met then, goes into the next step
    {
    balance=balance-w;//balance formula
    }


    return balance;

    }

    int accountnumber()

    {
    int a;

    cout<<"Please Enter your account number: "<<endl;
    cin>>a;

    while (a<0||a>49)
    {
    cout<<"Wrong account number"<<endl;
    cout<<"Please try again: "<<endl;
    cin>>a;
    }
    return a;
    }

    [code/n]

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Ideally, you want to use classes for this. It would be much cleaner. Then you just use an array of classes. However, if you have never used classes, you'd probably be best served starting with a simple structure. Here is a quick example:
    Code:
    struct Account
    {
        char name[80];
        float balance;
    };
    Then you'd make an array of these accounts, and change their names and what not when you need to.

    An array is best thought of as a list of items. Arrays start at zero and go to "size-1". Like so:
    Code:
    struct Account AllAccounts[10];
    
    AllAccounts[0].balance = 5.00;
    ...
    AllAccounts[9].balance = 1000.00;
    See here, we start at zero and go through nine. It looks like you understand the basics of arrays, but structures may be new to you.

    Ideally you'd use classes, but structs should suffice.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need a hint.
    By hyrule in forum C++ Programming
    Replies: 4
    Last Post: 09-04-2005, 09:31 PM
  2. need hint how to filter the results
    By kocika73 in forum C Programming
    Replies: 4
    Last Post: 01-29-2005, 05:27 PM
  3. hi! could anybody help me, a hint at the least
    By alvarorahul in forum C Programming
    Replies: 1
    Last Post: 07-07-2004, 02:37 AM
  4. i need hint...
    By jk81 in forum C Programming
    Replies: 3
    Last Post: 09-12-2002, 08:38 PM
  5. Programming hint required
    By abhijit in forum C++ Programming
    Replies: 2
    Last Post: 03-19-2002, 03:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21