I'm working on a project that has several banking menu options and calls all the accountID, passcode, balance, etc. from an object defined in the header.
Here's the thing I can call the accountID and passcode and accurately check them for validity but when I try to call GetBalance it runs but returns and updates a crazy long number that I definitely never put in the account Balance.
I need help calling the accurate account balance.
I think that even though I'm declaring an account variable that it isn't the one found with the code below from accountID and passcode.
I'll be checking in all night that s just partial code below if you want the whole thing in three parts : bankingSystem.h, bankingSystemDriver.cpp, and bankingSystem.cpp. just let me know. The header and driver are small and working fine.
Thanks!
Yes, the other codes would be useful. You could initialize the value in the default constructor. You declare it and define it just like any other function. It helps to prevent uninitialized variables.
1 2 3 4 5 6 7
BankingSystem(){
balance = 0;
deposit = 0;
//... and so on. You define every variable in the class here.
//If your variables contain another class, you have to define those too.
}
So this is all of the banking system.cpp. There's also a bankingsystemdriver.cpp but that's mostly just a menu and switch between menu items and there's also a bankingsystem.h header that mostly defines an Account class and a banking system class but the account is just getters and setters for accountid, passcode, first and last names, and balance and the banking system class implementation is all mostly fleshed out right here.
I feel like calling account.Getbalance is right but that it's calling them goofily.
I'll try initializing balance and deposit to zero though just in case they are having residual values.
Thanks!
So I just tried initializing deposit and balance to zero at the beginning of the deposit implementation and I'm still getting the crazy long negative number.
> I think that even though I'm declaring an account variable
> that it isn't the one found with the code below from accountID and passcode.
Exactly.
You never set `account' to anything meaningful.
I realize that but I'm also unsure of exactly how to set it correctly to correspond with the other info. I've tried using FindAccount to correspond with account like it does for accountID but so far it's a no go.
1) you can set the local account instance from accounts_[index], but then you have to store it back the modified instance.
1 2 3 4 5 6 7 8 9 10 11
Account account;
index = FindAccount (accountID);
if (index == current_num_accounts_)
{ /* not found */
}
else
{ account = accounts_[index]; // Copy the account instance
/* modifiy local account */
accounts_[index] = account; // Copy it back
}
2) Or simply use a pointer
1 2 3 4 5 6 7 8 9 10
Account * acct;
acct = FindAccount (accountID); // Returns a pointer or NULL if not found
if (! acct)
{ /* not found */
}
else
{ /* modifiy account via ptr */
acct->SetBalance (newbalance);
}
BTW, you don't need include guards around a .cpp file. A .cpp file should never be included.