I am making this program for a class and it works fine except for the daily interest rate for the checking account is off. The daily interest for the savings computes perfectly. The monthly interest rate for savings is 6% and for checking 3%.
Account.h
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <iostream>
#include <string>
using namespace std;
const int DAYS_PER_MONTH = 30;
class Account
{
public:
Account();
Account(double b);
void deposit(double amount);
void withdraw(double amount);
double get_balance() const;
private:
double balance;
};
#endif
Checking.h
#ifndef CHECKING_H
#define CHECKING_H
#include "Account.h"
class Checking: public Account
{
public:
Checking();
Checking(double b);
void daily_interest();
private:
};
#endif
Savings.h
#ifndef SAVIGS_H
#define SAVINGS_H
#include "Account.h"
class Savings : public Account
{
public:
Savings();
Savings(double b);
void daily_interest();
};
#endif
Account.cpp
#include <iostream>
#include "Account.h"
Account::Account(){
balance=0;
}
Account::Account(double b) {
balance=b;
}
void Account::deposit(double b) {
balance += b;
}
void Account::withdraw(double b) {
balance -= b;
}
double Account::get_balance() const {
return balance;
}
Checking.cpp
#include "Checking.h"
Checking::Checking() {
}
Checking::Checking(double b) {
this->deposit(b);
}
void Checking::daily_interest() {
double d = get_balance();
d = d * (.03/30);
this->deposit(d);
}
Savings.cpp
#include "Savings.h"
Savings::Savings(){
}
Savings::Savings(double b) {
this->deposit(b);
}
void Savings::daily_interest() {
double d = get_balance();
d = d * (.06/30);
this->deposit(d);
}
main.cpp
#include <iostream>
#include "Checking.h"
#include "Savings.h"
using namespace std;
int main()
{
Checking c = Checking(1000.0);
Savings s = Savings(1000.0);
for (int i = 1; i <= DAYS_PER_MONTH; i++)
{
c.deposit(i * 5);
c.withdraw(i * 2);
s.deposit(i * 5);
s.withdraw(i * 2);
c.daily_interest();
s.daily_interest();
if (i % 10 == 0)
{
cout << "day " << i << "\n";
cout << "Checking balance: " << c.get_balance() << "\n";
cout << "Savings balance: " << s.get_balance() << "\n";
}
}
return 0;
}
THE EXPECTED OUTPUT:
day 10
Checking balance: 1165.66
Savings balance: 1186.51
day 20
Checking balance: 1634.64
Savings balance: 1680.1
day 30
Checking balance: 2409.99
Savings balance: 2486.97
MY OUTPUT:
day 10
Checking balance: 1175.71
Savings balance: 1186.51
day 20
Checking balance: 1654.83
Savings balance: 1680.1
day 30
Checking balance: 2440.43
Savings balance: 2486.97