Hello! I have written written my own class, which includes a header file and a .cpp file. I have also written the driver for this program. Everything looks fine to me, but I am receiving about 20 random errors. I will post my code for all 3 files but I believe it is a problem that can be diagnosed using just the driver.

The program is a bank account program that adds new accounts, withdraws, deposits, updates, displays, etc. Any help would be greatly appreciated! Thanks.


HEADER

#include <iostream>
#include <string>
using namespace std;
class BankAccount
{
public:
 BankAccount();
 void deposit( double amt );
 void withdraw( double amt );
 void update();
 int getID();
 void setID( int anID );
 double getBalance();
 void setBalance( double amt );
 double getInterestRate();
 void setInterestRate( double amt );
 string getFirstName();
 void setFirstName( string theName );
 string getLastName();
 void setLastName( string theName );
 string getFullName();
 void display();
private:
 string firstName, lastName;
 double interestRate;
 int ID;
 double balance;
};

CLASS DEFINITION

#include "BankAccount.h"
/*
 Default Constructor
*/
BankAccount::BankAccount()
{
 ID = 0;
 balance = 0.0;
 interestRate = 0.0;
}
/*
 Adds deposit amount to current balance
*/
void BankAccount::deposit( double amt )
{
 balance = balance + amt;
}
/*
 Withdraws amount from current balance
 if there are sufficient funds.
 Fails quietly for insufficient funds.
*/
void BankAccount::withdraw( double amt )
{
 if( balance < amt ) return;
 balance = balance - amt;
}
/*
 Getter (accessor) for balance
*/
double BankAccount::getBalance()
{
 return balance;
}
/*
 Setter (mutator) for balance
*/
void BankAccount::setBalance( double amt )
{
 balance = amt;
}
/*
 Adds interest to account using current interest rate
*/
void BankAccount::update()
{
 balance = balance + balance * interestRate;
}
/*
 Getter for ID
*/
int BankAccount::getID()
{
 return ID;
}
/*
 Setter for ID
*/
void BankAccount::setID( int anID )
{
 ID = anID;
}
/*
 Getter for balance
*/
double BankAccount::getInterestRate()
{
 return interestRate;
}
/*
 Setter for interest rate
*/
void BankAccount::setInterestRate( double amt )
{
 interestRate = amt;
}
/*
 Getter for first name
*/
string BankAccount::getFirstName()
{
 return firstName;
}
/*
 Setter for first name
*/
void BankAccount::setFirstName( string theName )
{
 firstName = theName;
}
/*
 Getter for last name
*/
string BankAccount::getLastName()
{
 return lastName;
}
/*
 Setter for last name
*/
void BankAccount::setLastName( string theName )
{
 lastName = theName;
}
/*
 Getter for full name
*/
string BankAccount::getFullName()
{
 return lastName + ", " + firstName;
}
/*
 Displays info about about to console.
*/
void BankAccount::display()
{
 cout << "ID             : " << ID << endl;
 cout << "Name           : " << getFullName() << endl;
 cout << "Balance        : $" << balance << endl;
 cout << "Interest Rate  : " << interestRate << " %" << endl;
}

DRIVER

#include "BankAccount.h"
int getChoice();
void addBankAccount();
void withdrawAccount();
void depositAccount();
void updateAccounts();
void displayAccount();
void displayBalance();
void displayInfo();
int find(count, accts, id);
 
double tempRate;
double balance;
int count[10];
BankAccount accts[10];
int nextID = 100;
 
void main()
{
 int choice;
 do{
  choice = getChoice();
  if( choice == 1 ) addBankAccount();
  else if( choice == 2 ) withdrawAccount();
  else if( choice == 3 ) depositAccount();
  else if( choice == 4 ) updateAccounts();
  else if( choice == 5 ) displayAccount();
  else if( choice == 6 ) displayBalance();
  else if( choice == 7 ) displayInfo();
  if( choice > 8 || choice < 1 ) cout << "ERROR: Please enter valid choice (1-8)." << endl;
 } while( choice != 8 );
 
 
}
 
//This function displays the calculation menu.
int getChoice()
{
 int c;
 cout << "----------------------\n";
 cout << "1 - Add a new bank account.\n";
 cout << "2 - Withdraw from a specific bank account.\n";
 cout << "3 - Deposit to a specific account.\n";
 cout << "4 - Update all accounts which will add a fixed interest rate to each account.\n";
 cout << "5 - Display one specific bank accout.\n";
 cout << "6 - Display the average balance for all of the accounts.\n";
 cout << "7 - Display the current information for all accounts.\n";
 cout << "8 - Terminate the program.\n";
 cout << "----------------------\n";
 cout << "Enter number of choice --> ";
 cin >> c;
 return c;
}
//This function adds a bank account for a new member.
void addBankAccount()
{
 int count = 0;
 string temp;
 
 cout << "Please enter first name.";
 cin >> temp;
 accts[count].setFirstName(temp);
 cout << "Please enter last name.";
 cin >> temp;
 accts[count].setLastName(temp);
 cout << "Please enter balance.";
 cin >> balance;
 accts[count].setBalance(balance);
 cout << "Please enter interest rate (decimal form).";
 cin >> tempRate;
 accts[count].setInterestRate(tempRate);
 accts[count].setID(nextID);
 nextID = nextID + 1;
 count++;
 
 
}
 
// This function withdraws an amount from a specific account.
void withdrawAccount()
{
 int slot;
 double amt;
 int id;
 cout << "Enter ID number.";
 cin >> id;
 int slot = find(count, accts, id)
 cout << "Enter amount to withdraw.";
 cin >> amt;
 accts[slot].withdraw(amt);
 
 
}
 
//This function deposits an amount into a specific account.
void depositAccount()
{
 int slot;
 double amt;
 int id;
 cout << "Enter ID number.";
 cin >> id;
 int slot = find(count, accts, id)
 cout << "Enter amount to deposit.";
 cin >> amt;
 accts[slot].deposit(amt);
}
 
//This function updates all accounts using a fixed interest rate.
void updateAccounts()
{
 for (int i=0; i<count; i++)
  accts[i].update();
}
 
//This function displays one bank account.
void displayAccount()
{
 int target;
 cout << "Enter account number.";
 cin >> target;
 accts[target].display();
}
 
//This function displays the average balance of all accounts.
void displayBalance()
{
}
//This function displays the current information for all accounts.
void displayInfo()
{
 for (int i=0; i<count; i++)
  accts[i].display();
}
 
int find(count, accts, id)
{
 int index = 0;
 bool found = false;
 while ((!found) && (index < count))
  if (id == accts[index])
   found = true;
  else
   index++;
 if (found)
  return index;
 else
  return -1;
}

Hello! I have written written my own class, which includes a header file and a .cpp file. I have also written the driver for this program. Everything looks fine to me, but I am receiving about 20 random errors. I will post my code for all 3 files but I believe it is a problem that can be diagnosed using just the driver.

The program is a bank account program that adds new accounts, withdraws, deposits, updates, displays, etc. Any help would be greatly appreciated! Thanks.

Well, if it's OK with you, we'll just pick 20 random lines and randomly decide they must be wrong. :rolleyes:

Don't you think knowing what the errors are and where the errors are might be helpful in fixing the errors?

And please format your code. It's barely readable without proper indentation.
[edit]I see this has been mentioned at least 4 times. Are you bucking for an infraction? I really hate being ignored, and trying to read more unreadable code. Are you having a problem understanding good formatting guidelines?[/edit]

Sorry...I just thought it might be more obvious to someone else. These are errors that don't make sense to me because they worked before. I have declared what the error says is not and etc. So here are the errors I receive:

error C2065: 'count' : undeclared identifier
error C2065: 'accts' : undeclared identifier
error C2065: 'id' : undeclared identifier
error C2078: too many initializers
error C2040: 'count' : 'int [10]' differs in levels of indirection from ''unknown-type''
error C2040: 'accts' : 'BankAccount [10]' differs in levels of indirection from ''unknown-type''
error C2228: left of '.setFirstName' must have class/struct/union
error C2228: left of '.setLastName' must have class/struct/union
error C2228: left of '.setBalance' must have class/struct/union
error C2228: left of '.setInterestRate' must have class/struct/union
error C2228: left of '.setID' must have class/struct/union
error C2086: 'int slot' : redefinition
see declaration of 'slot'
error C2146: syntax error : missing ';' before identifier 'cout'
error C2228: left of '.withdraw' must have class/struct/union
error C2374: 'slot' : redefinition; multiple initialization
see declaration of 'slot'
error C2228: left of '.deposit' must have class/struct/union
error C2228: left of '.update' must have class/struct/union
error C2228: left of '.display' must have class/struct/union
error C2228: left of '.display' must have class/struct/union
error C2448: 'find' : function-style initializer appears to be a function ==========

HEADER

#include <iostream>
#include <string>
using namespace std;
class BankAccount
{
public:
         BankAccount();
         void deposit( double amt );
         void withdraw( double amt );
         void update();
         int getID();
         void setID( int anID );
         double getBalance();
         void setBalance( double amt );
         double getInterestRate();
         void setInterestRate( double amt );
         string getFirstName();
         void setFirstName( string theName );
         string getLastName();
         void setLastName( string theName );
         string getFullName();
         void display();
private:
         string firstName, lastName;
         double interestRate;
         int ID;
         double balance;
};

CLASS DEFINITION

#include "BankAccount.h"
/*
       Default Constructor
*/
BankAccount::BankAccount()
{
          ID = 0;
          balance = 0.0;
          interestRate = 0.0;
}
/*
          Adds deposit amount to current balance
*/
void BankAccount::deposit( double amt )
{
          balance = balance + amt;
}
/*
          Withdraws amount from current balance
          if there are sufficient funds.
          Fails quietly for insufficient funds.
*/
void BankAccount::withdraw( double amt )
{
          if( balance < amt ) return;
          balance = balance - amt;
}
/*
          Getter (accessor) for balance
*/
double BankAccount::getBalance()
{
          return balance;
}
/*
          Setter (mutator) for balance
*/
void BankAccount::setBalance( double amt )
{
          balance = amt;
}
/*
          Adds interest to account using current interest rate
*/
void BankAccount::update()
{
          balance = balance + balance * interestRate;
}
/*
          Getter for ID
*/
int BankAccount::getID()
{
          return ID;
}
/*
          Setter for ID
*/
void BankAccount::setID( int anID )
{
          ID = anID;
}
/*
          Getter for balance
*/
double BankAccount::getInterestRate()
{
           return interestRate;
}
/*
           Setter for interest rate
*/
void BankAccount::setInterestRate( double amt )
{
           interestRate = amt;
}
/*
           Getter for first name
*/
string BankAccount::getFirstName()
{
           return firstName;
}
/*
           Setter for first name
*/
void BankAccount::setFirstName( string theName )
{
           firstName = theName;
}
/*
           Getter for last name
*/
string BankAccount::getLastName()
{
            return firstName;
}
/*
            Setter for last name
*/
void BankAccount::setLastName( string theName )
{
             lastName = theName;
}
/*
            Getter for full name
*/
string BankAccount::getFullName()
{
             return lastName + ", " + firstName;
}
/*
             Displays info about about to console.
*/
void BankAccount::display()
{
             cout << "ID             : " << ID << endl;
             cout << "Name           : " << getFullName() << endl;
             cout << "Balance        : $" << balance << endl;
             cout << "Interest Rate  : " << interestRate << " %" << endl;
}

DRIVER

#include "BankAccount.h"
int getChoice();
void addBankAccount();
void withdrawAccount();
void depositAccount();
void updateAccounts();
void displayAccount();
void displayBalance();
void displayInfo();
int find(count, accts, id);
 
double tempRate;
double balance;
int count[10];
BankAccount accts[10];
int nextID = 100;

void main()
{
             int choice;
             do{
                       choice = getChoice();
                       if( choice == 1 ) addBankAccount();
                       else if( choice == 2 ) withdrawAccount();
                       else if( choice == 3 ) depositAccount();
                       else if( choice == 4 ) updateAccounts();
                       else if( choice == 5 ) displayAccount();
                       else if( choice == 6 ) displayBalance();
                       else if( choice == 7 ) displayInfo();
                       if( choice > 8 || choice < 1 ) cout << "ERROR: Please enter valid choice (1-8)." << endl;
              } while( choice != 8 );
 
 
}

//This function displays the calculation menu.
int getChoice()
{
             int c;
             cout << "----------------------\n";
             cout << "1 - Add a new bank account.\n";
             cout << "2 - Withdraw from a specific bank account.\n";
             cout << "3 - Deposit to a specific account.\n";
             cout << "4 - Update all accounts which will add a fixed interest rate to each account.\n";
             cout << "5 - Display one specific bank accout.\n";
             cout << "6 - Display the average balance for all of the accounts.\n";
             cout << "7 - Display the current information for all accounts.\n";
             cout << "8 - Terminate the program.\n";
             cout << "----------------------\n";
             cout << "Enter number of choice --> ";
             cin >> c;
             return c;
}
//This function adds a bank account for a new member.
void addBankAccount()
{
             int count = 0;
             string temp;
 
             cout << "Please enter first name.";
             cin >> temp;
             accts[count].setFirstName(temp);
             cout << "Please enter last name.";
             cin >> temp;
             accts[count].setLastName(temp);
             cout << "Please enter balance.";
             cin >> balance;
             accts[count].setBalance(balance);
             cout << "Please enter interest rate (decimal form).";
             cin >> tempRate;
             accts[count].setInterestRate(tempRate);
             accts[count].setID(nextID);
             nextID = nextID + 1;
             count++;
 

}

// This function withdraws an amount from a specific account.
void withdrawAccount()
{
             int slot;
             double amt;
             int id;
             cout << "Enter ID number.";
             cin >> id;
             int slot = find(count, accts, id)
             cout << "Enter amount to withdraw.";
             cin >> amt;
             accts[slot].withdraw(amt);

 
}

//This function deposits an amount into a specific account.
void depositAccount()
{
             int slot;
             double amt;
             int id;
             cout << "Enter ID number.";
             cin >> id;
             int slot = find(count, accts, id)
             cout << "Enter amount to deposit.";
             cin >> amt;
             accts[slot].deposit(amt);
}

//This function updates all accounts using a fixed interest rate.
void updateAccounts()
{
             for (int i=0; i<count; i++)
                       accts[i].update();
}

//This function displays one bank account.
void displayAccount()
{
            int target;
            cout << "Enter account number.";
            cin >> target;
            accts[target].display();
}

//This function displays the average balance of all accounts.
void displayBalance()
{
 
}
 
//This function displays the current information for all accounts.
void displayInfo()
{
            for (int i=0; i<count; i++)
                      accts[i].display();
}

int find(count, accts, id)
{
           int index = 0;
           bool found = false;
           while ((!found) && (index < count))
                      if (id == accts[index])
                                found = true;
                      else
                                index++;
            if (found)
                      return index;
            else
                      return -1;
}

Well, for starters in your function prototype for your function find(), you don't have any type values...haven't taken the time to decipher your code to figure out the other problems, but this will solve part of it...

I totally overlooked that. Thank you. I have got it down to one error now. It says that count has an undeclared identifier. I declared it in the addBankAccount function. I tried declaring it before main and passing it as a parameter but I got even more errors. Here is my new code for the driver:

#include "BankAccount.h"
int getChoice();
void addBankAccount();
void withdrawAccount();
void depositAccount();
void updateAccounts();
void displayAccount();
void displayBalance();
void displayInfo();
int find(int count, int accts[], int id);
 
double tempRate;
double balance;
BankAccount accts[10];
int nextID = 100;

void main()
{
            int choice;
            do{
                      choice = getChoice();
                      if( choice == 1 ) addBankAccount();
                      else if( choice == 2 ) withdrawAccount();
                      else if( choice == 3 ) depositAccount();
                      else if( choice == 4 ) updateAccounts();
                      else if( choice == 5 ) displayAccount();
                      else if( choice == 6 ) displayBalance();
                      else if( choice == 7 ) displayInfo();
                      if( choice > 8 || choice < 1 ) cout << "ERROR: Please enter valid choice (1-8)." << endl;
            } while( choice != 8 );
 
 
}

//This function displays the calculation menu.
 
int getChoice()
{
         int c;
         cout << "----------------------\n";
         cout << "1 - Add a new bank account.\n";
         cout << "2 - Withdraw from a specific bank account.\n";
         cout << "3 - Deposit to a specific account.\n";
         cout << "4 - Update all accounts which will add a fixed interest rate to each account.\n";
         cout << "5 - Display one specific bank accout.\n";
         cout << "6 - Display the average balance for all of the accounts.\n";
         cout << "7 - Display the current information for all accounts.\n";
         cout << "8 - Terminate the program.\n";
         cout << "----------------------\n";
         cout << "Enter number of choice --> ";
         cin >> c;
         return c;
}
 
//This function adds a bank account for a new member.
 
void addBankAccount()
{
          int count = 0;
          string temp;
 
          cout << "Please enter first name.";
          cin >> temp;
          accts[count].setFirstName(temp);
          cout << "Please enter last name.";
          cin >> temp;
          accts[count].setLastName(temp);
          cout << "Please enter balance.";
          cin >> balance;
          accts[count].setBalance(balance);
          cout << "Please enter interest rate (decimal form).";
          cin >> tempRate;
          accts[count].setInterestRate(tempRate);
          accts[count].setID(nextID);
          nextID = nextID + 1;
          count++;
 

}

// This function withdraws an amount from a specific account.
 
void withdrawAccount()
{
           double amt;
           int id;
           cout << "Enter ID number.";
           cin >> id;
           int slot = find(count, accts, id);
           cout << "Enter amount to withdraw.";
           cin >> amt;
           accts[slot].withdraw(amt);

 
}

//This function deposits an amount into a specific account.
 
void depositAccount()
{
           double amt;
           int id;
           cout << "Enter ID number.";
           cin >> id;
           int slot = find(count, accts, id);
           cout << "Enter amount to deposit.";
           cin >> amt;
           accts[slot].deposit(amt);
}

//This function updates all accounts using a fixed interest rate.
 
void updateAccounts()
{
        for (int i=0; i<count; i++)
                  accts[i].update();
}

//This function displays one bank account.
void displayAccount()
{
           int target;
           cout << "Enter account number.";
           cin >> target;
           accts[target].display();
}

//This function displays the average balance of all accounts.
 
void displayBalance()
{
 
}
 
//This function displays the current information for all accounts.
 
void displayInfo()
{
           for (int i=0; i<count; i++)
                     accts[i].display();
}

int find(int count, int accts[], int id)
{
           int index = 0;
           bool found = false;
           while ((!found) && (index < count))
                      if (id == accts[index])
                                found = true;
                     else
                                index++;
           if (found)
                     return index;
           else
                     return -1;
}

That's because count is only a local variable in your addBankAccount function...As soon as the function ends count goes away...try declaring it at the beginning of main then pass it to your addBankAccount function...you will also have to pass count to your other functions that make use of the count variable...

Ok...I have made those changes and now I have the two errors:

error C2664: 'find' : cannot convert parameter 2 from 'BankAccount [10]' to 'int []'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
 
error C2664: 'find' : cannot convert parameter 2 from 'BankAccount [10]' to 'int []'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Here is my new code for the driver:

#include "BankAccount.h"
int getChoice();
void addBankAccount(int);
void withdrawAccount(int);
void depositAccount(int);
void updateAccounts(int);
void displayAccount();
void displayBalance();
void displayInfo(int);
int find(int count, int accts[], int id);
 
 
double tempRate;
double balance;
BankAccount accts[10];
int nextID = 100;
 
void main()
{
      int count = 0;
      int choice;
      do{
          choice = getChoice();
          if( choice == 1 ) addBankAccount(count);
          else if( choice == 2 ) withdrawAccount(count);
          else if( choice == 3 ) depositAccount(count);
          else if( choice == 4 ) updateAccounts(count);
          else if( choice == 5 ) displayAccount();
          else if( choice == 6 ) displayBalance();
          else if( choice == 7 ) displayInfo(count);
          if( choice > 8 || choice < 1 ) cout << "ERROR: Please enter valid choice (1-8)." << endl;
      } while( choice != 8 );


}
 
//This function displays the calculation menu.
int getChoice()
{
     int c;
     cout << "----------------------\n";
     cout << "1 - Add a new bank account.\n";
     cout << "2 - Withdraw from a specific bank account.\n";
     cout << "3 - Deposit to a specific account.\n";
     cout << "4 - Update all accounts which will add a fixed   interest rate to each account.\n";
     cout << "5 - Display one specific bank accout.\n";
     cout << "6 - Display the average balance for all of the accounts.\n";
     cout << "7 - Display the current information for all accounts.\n";
     cout << "8 - Terminate the program.\n";
     cout << "----------------------\n";
     cout << "Enter number of choice --> ";
     cin >> c;
     return c;
}
//This function adds a bank account for a new member.
void addBankAccount(int count)
{

      string temp;

      cout << "Please enter first name.";
      cin >> temp;
      accts[count].setFirstName(temp);
      cout << "Please enter last name.";
      cin >> temp;
      accts[count].setLastName(temp);
      cout << "Please enter balance.";
      cin >> balance;
      accts[count].setBalance(balance);
      cout << "Please enter interest rate (decimal form).";
      cin >> tempRate;
      accts[count].setInterestRate(tempRate);
      accts[count].setID(nextID);
      nextID = nextID + 1;
      count++;

 
}
 
// This function withdraws an amount from a specific account.
void withdrawAccount(int count)
{
      double amt;
      int id;
      cout << "Enter ID number.";
      cin >> id;
      int slot = find(count, accts, id);
      cout << "Enter amount to withdraw.";
      cin >> amt;
      accts[slot].withdraw(amt);
 

}
 
//This function deposits an amount into a specific account.
void depositAccount(int count)
{
      double amt;
      int id;
      cout << "Enter ID number.";
      cin >> id;
      int slot = find(count, accts, id);
      cout << "Enter amount to deposit.";
      cin >> amt;
      accts[slot].deposit(amt);
}
 
//This function updates all accounts using a fixed interest rate.
void updateAccounts(int count)
{
      for (int i=0; i<count; i++)
           accts[i].update();
}
 
//This function displays one bank account.
void displayAccount()
{
       int target;
       cout << "Enter account number.";
       cin >> target;
       accts[target].display();
}
 
//This function displays the average balance of all accounts.
 
void displayBalance()
{
 
}
//This function displays the current information for all accounts.
 
void displayInfo(int count)
{
       for (int i=0; i<count; i++)
             accts[i].display();
}
 
int find(int count, int accts[], int id)
{
     int index = 0;
     bool found = false;
     while ((!found) && (index < count))
          if (id == accts[index])
             found = true;
         else
             index++;
     if (found)
         return index;
     else
         return -1;
}

That is because you have the wrong type in the prototype...you are passing acct which is of type BankAccount...therefore you need to change your prototype and header to something like this:

int find(int count, BankAccount accts[], int id);

hope this helps...

Geez...I have no idea why it's still not working! I made those corrections and now I have 8 errors which all seem to relate to the find function. Is it not correct?:

error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const 
 
error C2784: 'bool std::operator ==(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'int'
 
error C2784: 'bool std::operator ==(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'int'
 
error C2784: 'bool std::operator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'int'
 
error C2784: 'bool std::operator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'int'
 
error C2784: 'bool std::operator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'int'
 
error C2784: 'bool std::operator ==(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'int'
 
error C2677: binary '==' : no global operator found which takes type 'BankAccount' (or there is no acceptable conversion)

DRIVER CODE:

#include"BankAccount.h"
int getChoice();
void addBankAccount(int);
void withdrawAccount(int);
void depositAccount(int);
void updateAccounts(int);
void displayAccount();
void displayBalance();
void displayInfo(int);
int find(int count, BankAccount accts[], int id);
 
 
double tempRate;
double balance;
BankAccount accts[10];
int nextID = 100;
 
void main()
{
      int count = 0;
      int choice;
      do{
          choice = getChoice();
          if( choice == 1 ) addBankAccount(count);
          else if( choice == 2 ) withdrawAccount(count);
          else if( choice == 3 ) depositAccount(count);
          else if( choice == 4 ) updateAccounts(count);
          else if( choice == 5 ) displayAccount();
          else if( choice == 6 ) displayBalance();
          else if( choice == 7 ) displayInfo(count);
          if( choice > 8 || choice < 1 ) cout << "ERROR: Please enter valid choice (1-8)." << endl;
      } while( choice != 8 );


}
 
//This function displays the calculation menu.
int getChoice()
{
     int c;
     cout << "----------------------\n";
     cout << "1 - Add a new bank account.\n";
     cout << "2 - Withdraw from a specific bank account.\n";
     cout << "3 - Deposit to a specific account.\n";
     cout << "4 - Update all accounts which will add a fixed   interest rate to each account.\n";
     cout << "5 - Display one specific bank accout.\n";
     cout << "6 - Display the average balance for all of the accounts.\n";
     cout << "7 - Display the current information for all accounts.\n";
     cout << "8 - Terminate the program.\n";
     cout << "----------------------\n";
     cout << "Enter number of choice --> ";
     cin >> c;
     return c;
}
//This function adds a bank account for a new member.
void addBankAccount(int count)
{

      string temp;

      cout << "Please enter first name.";
      cin >> temp;
      accts[count].setFirstName(temp);
      cout << "Please enter last name.";
      cin >> temp;
      accts[count].setLastName(temp);
      cout << "Please enter balance.";
      cin >> balance;
      accts[count].setBalance(balance);
      cout << "Please enter interest rate (decimal form).";
      cin >> tempRate;
      accts[count].setInterestRate(tempRate);
      accts[count].setID(nextID);
      nextID = nextID + 1;
      count++;

 
}
 
// This function withdraws an amount from a specific account.
void withdrawAccount(int count)
{
      double amt;
      int id;
      cout << "Enter ID number.";
      cin >> id;
      int slot = find(count, accts, id);
      cout << "Enter amount to withdraw.";
      cin >> amt;
      accts[slot].withdraw(amt);
 

}
 
//This function deposits an amount into a specific account.
void depositAccount(int count)
{
      double amt;
      int id;
      cout << "Enter ID number.";
      cin >> id;
      int slot = find(count, accts, id);
      cout << "Enter amount to deposit.";
      cin >> amt;
      accts[slot].deposit(amt);
}
 
//This function updates all accounts using a fixed interest rate.
void updateAccounts(int count)
{
      for (int i=0; i<count; i++)
           accts[i].update();
}
 
//This function displays one bank account.
void displayAccount()
{
       int target;
       cout << "Enter account number.";
       cin >> target;
       accts[target].display();
}
 
//This function displays the average balance of all accounts.
 
void displayBalance()
{
 
}
//This function displays the current information for all accounts.
 
void displayInfo(int count)
{
       for (int i=0; i<count; i++)
             accts[i].display();
}
 
int find(int count, BankAccount accts[], int id)
{
     int index = 0;
     bool found = false;
     while ((!found) && (index < count))
          if (id == accts[index])
             found = true;
         else
             index++;
     if (found)
         return index;
     else
         return -1;
}
Member Avatar for iamthwee

Maybe you have to overload the == operator in your bankAccount class definition?

Maybe you have to overload the == operator in your bankAccount class definition?

I have already had the HEADER and CLASS DEFINITION approved and we are unable to make changes to them. How could I re-write the Find function so that it cooperates...maybe w/o using Bool?

Member Avatar for iamthwee

Like I said before.

if (id == accts[index])

since accts is of bankaccount class you have to overload the == operator. Or do something else.

I don't know how to do that. That's why I was asking if there is an easier way to write it.

I called getID from the Find function but I'm thinking it just overrides the ID I already passed it. The driver compiles, however, none of the functions work properly. Like when I call the deposit function and deposit an amount and then call the display account function the default info is displayed, which is all 0s for balance, interest rate, etc. I don't see anything wrong with the functions and I've been staring at it for a week so I was thinking if someone else looked at it they would spot the problem right away. Here is the new driver code:

#include"BankAccount.h"
int getChoice();
void addBankAccount(int);
void withdrawAccount(int);
void depositAccount(int);
void updateAccounts(int);
void displayAccount();
void displayBalance();
void displayInfo(int);
int find(int count, BankAccount accts[], int id);
 
 
double tempRate;
double balance;
BankAccount accts[10];
int nextID = 100;
 
void main()
{
     int count = 0;
     int choice;
     do{
          choice = getChoice();
         if( choice == 1 ) addBankAccount(count);
         else if( choice == 2 ) withdrawAccount(count);else if( choice == 3 ) depositAccount(count);
         else if( choice == 4 ) updateAccounts(count);
         else if( choice == 5 ) displayAccount();
         else if( choice == 6 ) displayBalance();
         else if( choice == 7 ) displayInfo(count);
         if( choice > 8 || choice < 1 ) cout << "ERROR: Please enter valid choice (1-8)." << endl;
      } while( choice != 8 );
 
 
}
 
//This function displays the calculation menu.
int getChoice()
{
    int c;
     cout << "----------------------\n";
     cout << "1 - Add a new bank account.\n";
     cout << "2 - Withdraw from a specific bank account.\n";
     cout << "3 - Deposit to a specific account.\n";
     cout << "4 - Update all accounts which will add a fixed   interest rate to each account.\n";
     cout << "5 - Display one specific bank accout.\n";
     cout << "6 - Display the average balance for all of the accounts.\n";
     cout << "7 - Display the current information for all accounts.\n";
     cout << "8 - Terminate the program.\n";
     cout << "----------------------\n";
     cout << "Enter number of choice --> ";
     cin >> c;
    return c;
}
//This function adds a bank account for a new member.
void addBankAccount(int count)
{
 
      string temp;
 
      cout << "Please enter first name.";
      cin >> temp;
      accts[count].setFirstName(temp);
      cout << "Please enter last name.";
      cin >> temp;
      accts[count].setLastName(temp);
      cout << "Please enter balance.";
      cin >> balance;
      accts[count].setBalance(balance);
      cout << "Please enter interest rate (decimal form).";
      cin >> tempRate;
      accts[count].setInterestRate(tempRate);
      accts[count].setID(nextID);
      nextID = nextID + 1;
      count++;
 
 
}
 
// This function withdraws an amount from a specific account.
void withdrawAccount(int count)
{
     double amt;
     int id;
      cout << "Enter ID number.";
      cin >> id;
     int slot = find(count, accts, id);
      cout << "Enter amount to withdraw.";
      cin >> amt;
      accts[slot].withdraw(amt);
 
 
}
 
//This function deposits an amount into a specific account.
void depositAccount(int count)
{
     double amt;
     int id;
      cout << "Enter ID number.";
      cin >> id;
     int slot = find(count, accts, id);
      cout << "Enter amount to deposit.";
      cin >> amt;
      accts[slot].deposit(amt);
}
 
//This function updates all accounts using a fixed interest rate.
void updateAccounts(int count)
{
     for (int i=0; i<count; i++)
           accts[i].update();
}
 
//This function displays one bank account.
void displayAccount()
{
      int target;
       cout << "Enter account number.";
       cin >> target;
       accts[target].display();
}
 
//This function displays the average balance of all accounts.
 
void displayBalance()
{
 
}
//This function displays the current information for all accounts.
 
void displayInfo(int count)
{
      for (int i=0; i<count; i++)
             accts[i].display();
}
 
int find(int count, BankAccount accts[], int id)
{
    int index = 0;
    bool found = false;
    while ((!found) && (index < count))
         if (id == accts[index])
             found = true;
        else
             index++;
    if (found)
        return index;
    else
        return -1;
}
Member Avatar for iamthwee

Instead of overloading the == operator you could write an isMatch() method.

Or perhaps you could even do something like.

if (id == accts[index].getID())

Member Avatar for iamthwee
//This function displays one bank account.
void displayAccount()
{

   int target;
   cout << "Enter account number.";
   cin >> target;

   accts[target].display();
}

And is that correct do you think? Assuming the account ID's start at 100?

How would I write an isMatch method? And can you tell why my other functions aren't working as well?

What do you mean? It's incorrect to assume the ID starts at 100? Does it matter since I have initialized that they do?

Member Avatar for iamthwee

I can't be asked to explain everything today.

Ready this carefully...there are still errors but it should get you to the next stage.

#include"BankAccount.h"

int getChoice();
void addBankAccount ( int );
void withdrawAccount ( int );
void depositAccount ( int );
void updateAccounts ( int );
void displayAccount ( int );
void displayBalance();
void displayInfo ( int );
int find ( int count, BankAccount accts[], int id );


double tempRate;
double balance;
BankAccount accts[10];
int nextID = 100;

int main()
{
   int count = 0;
   int choice;
   do
   {
      choice = getChoice();
      if ( choice == 1 ) addBankAccount ( count );
      else if ( choice == 2 ) withdrawAccount ( count );
      else if ( choice == 3 ) depositAccount ( count );
      else if ( choice == 4 ) updateAccounts ( count );
      else if ( choice == 5 ) displayAccount ( count );
      else if ( choice == 6 ) displayBalance();
      else if ( choice == 7 ) displayInfo ( count );
      if ( choice > 8 || choice < 1 ) cout << "ERROR: Please enter valid choice (1-8)." << endl;
   }
   while ( choice != 8 );


}

//This function displays the calculation menu.
int getChoice()
{
   int c;
   cout << "----------------------\n";
   cout << "1 - Add a new bank account.\n";
   cout << "2 - Withdraw from a specific bank account.\n";
   cout << "3 - Deposit to a specific account.\n";
   cout << "4 - Update all accounts which will add a fixed   interest rate to each account.\n";
   cout << "5 - Display one specific bank accout.\n";
   cout << "6 - Display the average balance for all of the accounts.\n";
   cout << "7 - Display the current information for all accounts.\n";
   cout << "8 - Terminate the program.\n";
   cout << "----------------------\n";
   cout << "Enter number of choice --> ";
   cin >> c;
   return c;
}
//This function adds a bank account for a new member.
void addBankAccount ( int count )
{
   string temp;

   cout << "Please enter first name.";
   cin >> temp;
   accts[count].setFirstName ( temp );
   cout << "Please enter last name.";
   cin >> temp;
   accts[count].setLastName ( temp );
   cout << "Please enter balance.";
   cin >> balance;
   accts[count].setBalance ( balance );
   cout << "Please enter interest rate (decimal form).";
   cin >> tempRate;
   accts[count].setInterestRate ( tempRate );
   accts[count].setID ( nextID );
   cout << "Your id is " << nextID << endl;
   nextID = nextID + 1;
   count++;
}

// This function withdraws an amount from a specific account.
void withdrawAccount ( int count )
{
   double amt;
   int id;
   cout << "Enter ID number.";
   cin >> id;
   int slot = find ( count, accts, id );
   cout << "Enter amount to withdraw.";
   cin >> amt;
   accts[slot].withdraw ( amt );
}

//This function deposits an amount into a specific account.
void depositAccount ( int count )
{
   double amt;
   int id;
   cout << "Enter ID number.";
   cin >> id;
   int slot = find ( count, accts, id );
   cout << "Enter amount to deposit.";
   cin >> amt;
   accts[slot].deposit ( amt );
}

//This function updates all accounts using a fixed interest rate.
void updateAccounts ( int count )
{
   for ( int i = 0; i < count; i++ )
      accts[i].update();
}

//This function displays one bank account.
void displayAccount ( int count )
{
   int target;
   cout << "Enter account number.";
   cin >> target;
   int slot = find ( count, accts, target );
   cout << "slot" << slot << endl;
   if ( target != -1 )
   {
      accts[slot].display();
   }
   cout << "error incorrect account number" << endl;}

//This function displays the average balance of all accounts.

void displayBalance()
{}
//This function displays the current information for all accounts.

void displayInfo ( int count )
{
   for ( int i = 0; i < count; i++ )
      accts[i].display();
}

int find ( int count, BankAccount accts[], int id )
{
   cout << "count" << count << endl;
   

   for ( int i = 0; i <= count; i++ )
   {
      if ( accts[i].getID() == id )
      {
         return i;
      }
      else
      {
         return -1;
         //this indicates id not found
      }
   }
}

Alright...I'm getting the hang of it. Can you see why after I the displayInfo function it skips right to the menu and does not display any of the accounts?

Member Avatar for iamthwee

Do you want me to debug this, or you?

Start putting a load of couts (or use a debugger) in places where you think it might be messing up. Go through your logic on paper if need be.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.