I can't get this "float t" to set an initial value of 0 so when the program gets to the withdraw() function it doesn't pass it to the deposit() function for them to first deposit money before making a withdrawal. I hope that made sense.
#include <iostream> #include <cmath> #include <string> using namespace std; class bank { public: float withdraw() { if(t == 0) { cout << "You must deposit money first before you may withdraw money." << endl; deposit(); } cout << "You have a total of " << t << " in your bank." << endl; cout << "How much would like to withdraw?" << endl; cin >> w; t = t - w; cout << "Your account balance is now: " << t << endl; cout << "What would you like to do:" << endl; cout << "withdraw | deposit | balance | quit" << endl; cin >> r; if(r == "withdraw") { withdraw(); } else if(r == "balance") { cout << "Your account balance is: "; return t; } else if(r == "deposit") { deposit(); } } float deposit() { cout << "How much would you like to deposit?" << endl; cin >> d; t = t + d; cout << "Your account balance is now: " << t << endl; cout << "What would you like to do:" << endl; cout << "withdraw | deposit | balance | quit" << endl; cin >> r; } private: string r; //string variable for response. float t; //total account balance. float d; //total amount you are depositing. float w; //total amount you are withdrawing. }; int main() { bank one; one.deposit(); return 0; }
I keep getting an error if I try something like "float t = 0;" it keeps saying:
error: ISO c++ forbids initialization of member 't'
error: making 't' static
error: ISO c++ forbids in-class initialization of non-const static member 't'
**I know it has no return in the deposit() function, I haven't completed it yet so don't worry about that**
Anyone who can help, I really appreciate it