I'm trying to print the balance from a checking and savings account. I know you can't return a value using the void function, but in what way can I show the balances for both accounts?
#ifndef ACCOUNT_H #define ACCOUNT_H // Account.h // 4/8/14 // description class Account { private: double balance; double interest_rate; // for example, interest_rate = 6 means 6% public: Account(); Account(double); void deposit(double); bool withdraw(double); // returns true if there was enough money, otherwise false double query(); void set_interest_rate(double rate); double get_interest_rate(); void add_interest(); }; #endif // Bank.cpp // 4/12/14 // description #include <iostream> #include <string> #include "Bank.h" using namespace std; Bank::Bank(): checking(0), savings(0) { } Bank::Bank(double checking_amount, double savings_amount): checking(checking_amount), savings(savings_amount){; checking = Account(checking_amount); savings = Account(savings_amount); } void Bank::deposit(double amount, string account) { if (account == "S") { savings.deposit(amount); } if (account == "C") { checking.deposit(amount); } } void Bank::withdraw(double amount, string account) { if (account == "S") { savings.withdraw(amount); } if (account == "C") { checking.withdraw(amount); } } void Bank::transfer(double amount, string account) { if (account == "S") { savings.deposit(amount); checking.withdraw(amount); } if (account == "C") { checking.deposit(amount); savings.withdraw(amount); } } void Bank::print_balances() { cout << savings << endl; cout << checking << endl; } #ifndef BANK_H #define BANK_H // Bank.h // 4/12/14 // description #include <string> #include "Account.h" using namespace std; class Bank { private: Account checking; Account savings; public: Bank(); Bank(double savings_amount, double checking_amount); void deposit(double amount, string account); void withdraw(double amount, string account); void transfer(double amount, string account); void print_balances(); }; #endif I'm getting 2 errors under void Bank::print_balances(). It just says:
"no match for 'operator<<' in 'std::cout << ((Bank*)this) ->Bank::savings'" I was reading a lot about it, but all I learned was since "checking" and "savings" are an account type, it won't work. My previous project similar, and I had "double" types instead so I was able to return a value.
Sorry if the format is wrong. First time posting on this site.
Account, you have to overload the operator to tell it how.BankandAccount), theBankmember definitions are provided before the declarations forcing others to scan back and forth in the code...