hi im new to daniweb im currently working on a piece of work. the idea is to create a bank account with deposit and withdrawal functions. create student business and current accounts (this is all roughly done and a case of copying and pasting for each account type with a different set of questions) . what it requires me to do is allow 10 accounts to be opened and then allow the user to search for each one and deposit and withdraw from each one. would anyone have any suggestions on how i could do this. below is my code so far and thankyou for taking the time to look. also it requires me to take an object orientated approach and im rather confused what this entails, any suggestions again would be appreciated.

1st - BANK.CPP

#include <iostream>
#include <string>  

using namespace std;

int main()
{
// Declare Variables
	int withdraw;
	int sqone;
	int sqtwo;
	int bone;
	string colname;
	string name;
	string sname;
	int housenumber;
	string postcode;
	string dob;
	string telno;
	double acctbalance, deposit;
	char choices;
	acctbalance = 0;

//inputs, get the name and initial balance

          
	do
	{
cout<<"\n\n-------------------------------------------------\n";  
cout << "What do you wish to do?" << endl;  
cout << "O open new account" << endl;  
cout << "C open new Business account" << endl;  
cout << "D Deposit Money" << endl;  
cout << "W Withdraw Money" << endl;  
cout << "B Display Balance" << endl;  
cout << "P Bank Account Details" << endl;  
cout << "Q Quit" << endl<<endl;cout<<"Enter selection: ";  
cin >> choices;  
switch (choices)  
{  
//add account type options here under letter O  
case 'O':  
case 'o':  
{  
    {  
        cout<<"\n\n-------------------------------------------------\n";  
        cout << "What Account Do You Wish To Open?" << endl;  
        cout << "S Student Account" << endl;  
        cout << "C Current Account" << endl;  
        cout << "B Business Account" << endl;  
        cout<<"Enter selection: ";  
        cin >> choices;  
        break;// Need a break statement here  
    }  
}  
				 
				 
				 
	//STUDENT ACCOUNT			 
				 case 'S':
                 case 's':
                          {
                          cout<<"Please Answer The Following Questions / 1 = Yes, 2 = No "<<endl;
                          cout<<"---------------------------------------------------------"<<endl;
						  cout<<"Are You A Full Time Student?"<<endl;
                          cin>>sqone;
                          if (sqone == 0)
                          {
                                       cout << "sorry that is not a valid option"<< endl;
                                       break;
                          }
						  if (sqone == 2)
                          {
                                       cout<<"Sorry You Are Not Valid For This Account"<<endl;
                                       break;
                          }
                          else if (sqone == 1)
                          {
                                       cout<<"Thankyou"<<endl;
									   cout<<"Have You Got Documentation To Support Your Course And Accomadation?"<<endl;
										cin>>sqtwo;
						  if (sqtwo == 0)
							  {
                                       cout << "sorry that is not a valid option"<< endl;
                                       break;
                          }
						  if (sqtwo == 1)
                          {
										cout<<"Thankyou you are elegible for this account"<<endl;
										cout<<"------------------------------------------"<<endl;
									   	cout << "Colleague Name: ";
										cin >> colname;
										cout << "Enter First Name: ";
										cin >> name;
										cout << "Enter Surname: ";
										cin >> sname;
										cout << "House Number: ";
										cin >> housenumber;
										cout << "Post Code: ";
										cin >> postcode;
										cout << "Date Of Birth: ";
										cin >> dob;
										cout << "Telephone Number: ";
										cin >> telno;
										cout << "Please enter initial balance: ";
										cin >> acctbalance;
										break;

                       
                          }
							else if (sqtwo == 2)
                          {
                                       cout<<"Sorry You Are Not Valid For This Account"<<endl;
                                       break;
						  }
						
                 

	  //BUSINESS ACCOUNT
						case 'c':
                 case 'C':
                          {
                          cout<<"Please Answer The Following Questions / 1 = Yes, 2 = No "<<endl;
                          cout<<"---------------------------------------------------------"<<endl;
						  cout<<"Have you got documentation showing your business details?"<<endl;
                          cin>>bone;
                          if (bone == 0)
                          {
                                       cout << "sorry that is not a valid option"<< endl;
                                       break;
                          }
						  if (bone == 2)
                          {
                                       cout<<"Sorry You Are Not Valid For This Account"<<endl;
                                       break;
                          }
                          if (bone == 1)
                          {
                                       
									   cout<<"We Will Now Proceed To Open This Account For You?"<<endl;
										cout<<"------------------------------------------"<<endl;
									   	cout << "Colleague Name: ";
										cin >> colname;
										cout << "Enter First Name: ";
										cin >> name;
										cout << "Enter Surname: ";
										cin >> sname;
										cout << "House Number: ";
										cin >> housenumber;
										cout << "Post Code: ";
										cin >> postcode;
										cout << "Date Of Birth: ";
										cin >> dob;
										cout << "Telephone Number: ";
										cin >> telno;
										cout << "Please enter initial balance: ";
										cin >> acctbalance;
										break;

                       
                          }
							else if (sqtwo == 2)
                          {
                                       cout<<"Sorry You Are Not Valid For This Account"<<endl;
                                       break;
						  }
						  }
						  }
						  }
		 
				 
				 
				 case 'D':
                 case 'd':
                          {
                          cout << "Enter amount to be deposited: "<< endl;
                          cin >>deposit;
                          if (deposit > 0)
                                      {
                                      acctbalance = acctbalance + deposit;
                                      if (deposit >= 10000)
                                      cout <<"Big Money!"<<endl;
                                      break;
                                      }
                          if (deposit == 0 || deposit < 0)
                                      {
                                      cout <<"Amount must be greater than 0";
                                      break ;
                                      }
                          }
                 case 'B':
                 case 'b':
                          {
                          cout <<"Your current balance is $ "<<acctbalance<<'.'<<endl;
                          if (acctbalance ==0)
                                          cout <<"Big Money!"<<endl;
                          break;
                          }
                 case 'W':
                 case 'w':
                          {
                          cout<<"Please enter amount to withdraw "<<endl;
                          cout<<"Withdrawal must be multiple of 10"<<endl;
                          cin>>withdraw;
                          if (withdraw == 00)
                          {
                                       cout << "Can't withdraw 0 dollars"<< endl;
                                       break;
                          }
                          if (withdraw < 0)
                          {
                                       cout<<"Must be a positive number"<<endl;
                                       break;
                          }
                          if (withdraw > acctbalance)
                          {
                                       cout<<"Can't withdraw more than balance"<<endl;
                                       break;
                          }
                          if ((withdraw % 10) !=0)
                          {
                                       cout<<"amount must be a multiple of 20"<<endl;
                                       break;
                          }
                          else
                          {
                                       acctbalance=acctbalance - withdraw;
                                       cout<<"Here is your money. Enjoy!"<< endl;
                                       break;
                          }
						  case 'P':
                 case 'p':
                          {
							  cout << "\n\n"<<endl;
							  cout <<"Personal Details"<<endl;
							  cout <<"First Name : "<<name<<endl;
							  cout <<"Surname : " <<sname<<endl;
							  cout <<"house number : " <<housenumber<<endl;
							  cout <<"post code : " <<postcode<<endl;
							  cout <<"telephone number : " <<telno<<endl;

                          cout <<"Your current balance is £ "<<acctbalance<<'.'<<endl;
                          if (acctbalance ==0)
                                          cout <<"Big Money!"<<endl;
                          break;
                          }
                          }

                 case 'Q':
                 case 'q':
                          {
                                       cout<<"Thank for using our services have a nice day!"<<endl;
                                       break;
                          }
        }
        }while (choices != 'q' && choices != 'Q');
        return 0;
}

and the 2nd class - account.h

#include <iostream>
#include <string>

using namespace std;

class Account
{
  double money;         // amount of money held by this account
  double interestRate;  // a monthly or yearly interestrate, depending on how the account is to be used.


public:

     // create an account with an initial amountand a specified interest rate
  Account(double amount, double percent)
  {
    money = amount;
    interestRate = percent;
  }

     // return the account's balance
  double balance()
  {
    return money;
  }

     // add money to the account
  void deposit(double amount)
  {
    money += amount;
  }

     // substract money from the account
  void withdraw(double amount)
  {
    
  }

     // add money according to the interest rate.
  void addInterest()
  {
    money *= (1 + interestRate/100.0);
         
  }

};

thankyou again

>allow 10 accounts to be opened and then allow the user to search
>for each one and deposit and withdraw from each one
Well, start by allowing one account and work up from there. As a first attempt, I would suggest an array of account class objects. You need to write the account class, of course. Overall the problem is more tedious than difficult. Here's a basic example:

#include <ios>
#include <iostream>
#include <iomanip>
#include <limits>
#include <stdexcept>
#include <string>

class Account {
  std::string _name;

  // Represented by the number of pennies, so on a
  // 32-bit system these accounts are limited to
  // $42,949,672.96. Beware arithmetic overflow
  unsigned long _balance;
public:
  Account(): _balance ( 0 ) {}

  Account ( std::string name, unsigned long initial_balance )
    : _name ( name ), _balance ( initial_balance )
  {}

  std::string Name() const
  {
    return _name;
  }

  unsigned long Balance() const
  {
    return _balance;
  }

  unsigned long Credit ( unsigned long amount )
  {
    return _balance += amount;
  }

  unsigned long Debit ( unsigned long amount )
  {
    if ( amount > _balance ) {
      throw std::runtime_error ( 
        "Cannot debit more than the account contains" );
    }

    return _balance -= amount;
  }

  friend std::ostream& operator<< ( std::ostream& out, const Account& acct )
  {
    return out<< acct._name <<": "<< acct._balance / 100 <<"."
      << std::setfill ( '0' ) << std::setw ( 2 ) << acct._balance % 100;
  }
};

int main()
{
  Account accts[10];
  int n = 0;

  while ( true ) {
    std::cout<<"> ";

    std::string command;

    if ( !getline ( std::cin, command ) || command == "q" )
      break;

    if ( command == "new" ) {
      std::string name;
      unsigned long balance;

      std::cout<<"Name: ";
      getline ( std::cin, name );

      std::cout<<"Balance: ";
      std::cin>> balance;
      std::cin.ignore();

      accts[n++] = Account ( name, balance );
    }
    else if ( command == "credit" ) {
      std::string name;
      unsigned long amount;

      std::cout<<"Account name: ";
      getline ( std::cin, name );

      std::cout<<"Amount to debit: ";
      std::cin>> amount;
      std::cin.ignore();

      for ( int i = 0; i < n; i++ ) {
        if ( accts[i].Name() == name ) {
          try {
            accts[i].Debit ( amount );
          } catch ( std::exception& ex ) {
            std::cout<< ex.what() <<'\n';
          }
        }
      }
    }
    else if ( command == "debit" ) {
      std::string name;
      unsigned long amount;

      std::cout<<"Account name: ";
      getline ( std::cin, name );

      std::cout<<"Amount to credit: ";
      std::cin>> amount;
      std::cin.ignore();

      for ( int i = 0; i < n; i++ ) {
        if ( accts[i].Name() == name )
          accts[i].Credit ( amount );
      }
    }
    else if ( command == "report" ) {
      for ( int i = 0; i < n; i++ )
        std::cout<< accts[i] <<'\n';
    }
    else
      std::cout<<"Unrecognized command\n";
  }
}

Just as an aside, in this economy a short might be a more accurate variable type than an unsigned long for the balance. Hopefully we don't see the day where char types have enough memory to successfully handle the balances!

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