help with program errors for savings account program


Hi I am having trouble figuring out why i am getting the following error when I run the program. I am getting this error

51 II\FinalProjectSavingAccount.cpp [Warning] passing `double' for converting 1 of `SavingsAccount::SavingsAccount(int)'

77 II\FinalProjectSavingAccount.cpp expected `}' at end of input

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  #include <iostream>

using namespace std;

class SavingsAccount
{
	public:
		SavingsAccount(){}
		SavingsAccount(int value);
		~SavingsAccount(){}
		static float annualInterestRate;
		void calculateMonthlyInterest();
		static void modifyIntererestRate(float value);
		float GetBalance() const { return savingsBalance; }
	private:
		// Each member of the class contains a private data member 
		// savingsBalance indicating the amount the saver currently has 
		// on deposit.
		float savingsBalance;
};

// copy constructor to initialize the value at instantiation
SavingsAccount::SavingsAccount(int value)
{
	savingsBalance = value;
}

// Use a static data member annualInterestRate to store the annual interest
// rate for each of the savers. 
float SavingsAccount::annualInterestRate = 0;

// Provide member function calculateMonthlyInterest that calculates the 
// monthly interest by multiplying the savingsBalance by annualInterestRate
// divided by 12 and then adds this interest to savingsBalance.
void SavingsAccount::calculateMonthlyInterest()
{
	savingsBalance += ((savingsBalance * annualInterestRate) / 12);
}

//Provide a static member function modifyIntererestRate that sets the 
// static annualInterestRate to a new value. 
void SavingsAccount::modifyIntererestRate(float value)
{
	annualInterestRate = value;
}

int main()
{
	// Instantiate two different objects of class SavingsAccount, saver1 
	// and saver2, with balances of $2000.00 and $3000.00, respectively.
	SavingsAccount saver1(2000.00);
	SavingsAccount saver2(3000.00);

	// Set the annualInterestRate to 3%.
	SavingsAccount::modifyIntererestRate(3);

	// Then calculate the monthly interest and print the new balances for 
	// each of the savers. 
	saver1.calculateMonthlyInterest();
	cout << "Saver 1 Savings Balance: $" << saver1.GetBalance() << endl;
	saver2.calculateMonthlyInterest();
	cout << "Saver 2 Savings Balance: $" << saver2.GetBalance() << endl;

	cout << endl;

	// Then set the annualInterestRate to 4%
	SavingsAccount::modifyIntererestRate(4);

	// and calculate the next month's interest and print the new balances 
	// for each of the savers
	saver1.calculateMonthlyInterest();
	cout << "Saver 1 Savings Balance: $" << saver1.GetBalance() << endl;
	saver2.calculateMonthlyInterest();
	cout << "Saver 2 Savings Balance: $" << saver2.GetBalance() << endl;

	cout << endl;
	return 0;
1
2
SavingsAccount saver1(2000.00);
SavingsAccount saver2(3000.00);

For the first message, you're passing a double value here, but the constructor expects an int.

For the second message, it looks like there's a closing brace missing at the end of the main function.
Thanks ETDecius.. That work.

.but now I want to do it in oop format.. when I did i got the following errors

3 II\Final project\mainSavingAccount.cpp In file included from mainSavingAccount.cpp

5:2 C:\Users\User\SkyDrive\programming II\Final project\savingsAccount.h invalid preprocessing directive #inclue

Here is the code.

savingsAccount.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
	public:
		SavingsAccount(){}
		SavingsAccount(double value);
		~SavingsAccount(){}
		static float annualInterestRate;
		void calculateMonthlyInterest();
		static void modifyIntererestRate(float value);
		float GetBalance() const { return savingsBalance; }
	private:
		// Each member of the class contains a private data member 
		// savingsBalance indicating the amount the saver currently has 
		// on deposit.
		float savingsBalance;
};


#endif



savingsAccount.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

//function definition for SavingsAccount class

#include "savingsAccount.h"

// copy constructor to initialize the value at instantiation
SavingsAccount::SavingsAccount(double value)
{
	savingsBalance = value;
}

// Use a static data member annualInterestRate to store the annual interest
// rate for each of the savers. 
float SavingsAccount::annualInterestRate = 0;

// Provide member function calculateMonthlyInterest that calculates the 
// monthly interest by multiplying the savingsBalance by annualInterestRate
// divided by 12 and then adds this interest to savingsBalance.
void SavingsAccount::calculateMonthlyInterest()
{
	savingsBalance += ((savingsBalance * annualInterestRate) / 12);
}

//Provide a static member function modifyIntererestRate that sets the 
// static annualInterestRate to a new value. 
void SavingsAccount::modifyIntererestRate(float value)
{
	annualInterestRate = value;
}



mainsavingAccount.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

#include <cstdlib>
#include <iostream>
#include "savingsAccount.h"

using namespace std;

int main(int argc, char *argv[])
{
  	// Instantiate two different objects of class SavingsAccount, saver1 
	// and saver2, with balances of $2000.00 and $3000.00, respectively.
	SavingsAccount saver1(2000.00);
	SavingsAccount saver2(3000.00);

	// Set the annualInterestRate to 3%.
	SavingsAccount::modifyIntererestRate(3);
	
	cout << "Saver 1 Savings Balance: $" << saver1.GetBalance() << endl;
	cout << "Saver 2 Savings Balance: $" << saver2.GetBalance() << endl;
	cout << endl;

	// Then calculate the monthly interest and print the new balances for 
	// each of the savers. 
	saver1.calculateMonthlyInterest();
	cout << "Saver 1 Savings Balance: $" << saver1.GetBalance() << endl;
	saver2.calculateMonthlyInterest();
	cout << "Saver 2 Savings Balance: $" << saver2.GetBalance() << endl;

	cout << endl;

	// Then set the annualInterestRate to 4%
	SavingsAccount::modifyIntererestRate(4);

	// and calculate the next month's interest and print the new balances 
	// for each of the savers
	saver1.calculateMonthlyInterest();
	cout << "Saver 1 Savings Balance: $" << saver1.GetBalance() << endl;
	saver2.calculateMonthlyInterest();
	cout << "Saver 2 Savings Balance: $" << saver2.GetBalance() << endl;

	cout << endl;
  
  
  
    system("PAUSE");
    return EXIT_SUCCESS;
}

The error message basically says that you misspelled "#include" (you wrote "#inclue"). The typo is probably in the first few lines of savingsAccount.h that you neglected to show.

Random Note:
Your constructor takes in a double as a parameter, but your data member is a float, so you will lose precision in the conversion. Be consistent with your data types.
Topic archived. No new replies allowed.