I'm learning how to use static members/functions and what the question provided I've came up with this so far. When I run this code I get the follow messagei changed around some settings trying to see if I could fix it when i changed my print to a double this error would go away but then i'd get some linker error. i went the the MS place to see if i could understand the error better but no like. Any help would be greatQuote:
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
Code:header file:
class SavingsAccount
{
public:
SavingsAccount( double, double );
void setAnnualInterestRate( double );
void calculateMonthlyInterest();
static void modifyInterestRate( double );
void print();
private:
double savingsBalance;
static double annualInterestRate;
};
body:
#include <iostream>
#include <iomanip>
using namespace std;
#include "savings.h"
double SavingsAccount::annualInterestRate = 0.0; //inital rate
SavingsAccount::SavingsAccount( double bal, double annual )
{
savingsBalance = ( bal >= 0.0 ? bal : 0.0 );
setAnnualInterestRate( annual );
}
void SavingsAccount::setAnnualInterestRate( double annual)
{
annualInterestRate = ( annual >= 0.0 && annual <= 1.0) ? annual : .03;
}
void SavingsAccount::calculateMonthlyInterest()
{
savingsBalance += savingsBalance * ( annualInterestRate / 12);
}
void SavingsAccount::modifyInterestRate( double interest )
{
annualInterestRate = (interest >= 0.0 && interest <= 1.0) ? interest : .04;
}
void SavingsAccount::print()
{
cout << setprecision(2) << "$" << savingsBalance;
}
int Main()
{
SavingsAccount server1(2000,.03);
SavingsAccount server2(3000,.03);
cout << "Initial Balance For server1 Is: " << server1.print();
cout << "\nInitial Balance For server2 Is: " << server2.print() << "\n\n";
system("PAUSE");
return 0;
};