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]
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Maybe you have to overload the == operator in your bankAccount class definition?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Like I said before.
if (id == accts[index])
since accts is of bankaccount class you have to overload the == operator. Or do something else.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Instead of overloading the == operator you could write an isMatch() method.
Or perhaps you could even do something like.
if (id == accts[index].getID())
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
//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?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
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
}
}
}
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439