Error C2688 on Passby References

Hi, so this is my first post here, so I hope I'm formatting all this correctly. I'm currently writing a mortgage payment calculator program that will calculate the monthly payments on a loan given the loan
amount, the yearly interest rate, number of years (the length of the loan in years), and total interest paid over the
period of the loan. The process repeats until negative loan amount is entered. As an output, program prints input
values, the monthly payment, and the total interest paid on the display.

Here is the included error message from the compiler.
1>------ Build started: Project: HW7, Configuration: Debug Win32 ------
1> DylanDunn_B7-1.cpp
1>d:\visual studio 2013\projects\hw7\hw7\dylandunn_b7-1.cpp(81): error C2668: 'DeterminePayment' : ambiguous call to overloaded function
1> d:\visual studio 2013\projects\hw7\hw7\dylandunn_b7-1.cpp(42): could be 'void DeterminePayment(float,float,int &,float &)'
1> d:\visual studio 2013\projects\hw7\hw7\dylandunn_b7-1.cpp(11): or 'void DeterminePayment(float,float,int,float &)'
1> while trying to match the argument list '(float, float, int, float)'

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I am also unsure if my while loop is going to function correctly once this error is fixed.

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
78
79
80
81
82
83
#include <iostream>

using namespace std;
void GetLoanAmt(float& loanAmount);//gets loan amount from user
void GetRest(float& monthlyInterest, int & numberOfYears);//calls GetInterest function and gets 
//numberOfYears from user
void GetInterest(float& monthlyInterest);//gets yearly interest from user
void DeterminePayment(float loanAmount, float monthlyInterest, int numberOfPayments, float&
	payment);//calculates monthly payment amount
void PrintResults(float loanAmount, float yearlyInterest,
	int numberOfPayments, float payment,
	float totalInterest);//prints results on screen.


void GetLoanAmt(float& loanAmount)
{
	cout << "Welcome to input loan amount program." << endl;
	cout << "Please remember that a negative loan amount terminates the program."<< endl;
	cout << "Please enter a loan amount: ";
	cin >> loanAmount;
}
	void GetRest(float& monthlyInterest, int & numberOfYears)
{
		cout << "Please enter an interest rate: "<<endl;
		cin >> monthlyInterest;
		cout << "Enter number of years on the loan :  "<<endl;
		cin >> numberOfYears;
	}
void GetInterest(float& monthlyInterest)
{
	float yearlyInterest = 0;

	yearlyInterest = monthlyInterest * 12;
	cout << endl;
}
void DeterminePayment(float loanAmount, float monthlyInterest, int & numberOfPayments, float & payment)
{

	payment = loanAmount * monthlyInterest;

	cout << endl;
}
void PrintResults(float loanAmount, float yearlyInterest, int numberOfPayments, float payment, float totalInterest)
{
	int numberOfYears; 
	totalInterest = yearlyInterest * numberOfYears;
	cout << "Here are the results." << endl;
	cout << "Loan Amount: " << loanAmount<< endl;
	cout << "Interest Rate: " << yearlyInterest << endl;
	cout << "Number of Payments: " << numberOfPayments << endl;
	cout << "Monthly Payment: " << payment << endl;
	cout << "Total Interest Paid: " << totalInterest << endl;
}


int main()
{
	float loanAmount;
	float monthlyInterest;
	int numberOfYears;
	int numberOfPayments;
	float payment;
	float yearlyInterest;
	float totalInterest;


	cout << "Please remember that negative loan amount terminates the program!!!" << endl;
	cout << "Please enter a loan amount: " << endl;
	cin >> loanAmount;
	while (loanAmount < 0)
	{
		cout << "Thanks for your business. BYE! Hope to see you later.You will receive a customer satisfaction survey to your email address." << endl;
	}
	GetLoanAmt(loanAmount);
	GetRest(monthlyInterest, numberOfYears);
	GetInterest(monthlyInterest);
	DeterminePayment(loanAmount, monthlyInterest, numberOfPayments, payment);
	PrintResults(loanAmount, yearlyInterest, numberOfPayments,  payment, totalInterest);

	return 0;
}

Last edited on
Your function prototype and implementation do not agree.
See lines 8 and 36:
1
2
3
4
5
6
 
void DeterminePayment (float loanAmount, float monthlyInterest, 
int numberOfPayments, float & payment);

void DeterminePayment (float loanAmount, float monthlyInterest, 
int & numberOfPayments, float & payment)


Note the third argument.
No errors now, but my code is not functioning the way it needs to. After entering the number of years, the program doesn't allow me to do anything else, nor does it display anything. Also, I'd like help on how to get the program to stop completely with my while loop.

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
78
79
80
81
82
83
84
85
86
#include <iostream>

using namespace std;
void GetLoanAmt(float& loanAmount);//gets loan amount from user
void GetRest(float& monthlyInterest, int & numberOfYears);//calls GetInterest function and gets 
//numberOfYears from user
void GetInterest(float& monthlyInterest);//gets yearly interest from user
void DeterminePayment(float loanAmount, float monthlyInterest, int numberOfPayments, float&
	payment);//calculates monthly payment amount
void PrintResults(float loanAmount, float yearlyInterest,
	int numberOfPayments, float payment,
	float totalInterest);//prints results on screen.


void GetLoanAmt(float& loanAmount)
{
	cout << endl;
}
	void GetRest(float& monthlyInterest, int & numberOfYears)
{
		cout << "Please enter an interest rate: " << endl;
		cin >> monthlyInterest;
		cout << "Enter number of years on the loan : " << endl;
		cin >> numberOfYears;
	}
void GetInterest(float& monthlyInterest)
{
	float yearlyInterest = 0;

	yearlyInterest = monthlyInterest * 12;
	cout << endl;
}
void DeterminePayment(float loanAmount, float monthlyInterest, int  numberOfPayments, float & payment)
{

	payment = loanAmount * monthlyInterest;

	cout << endl;
}
void PrintResults(float loanAmount, float yearlyInterest, int numberOfPayments, float payment, float totalInterest)
{
	int numberOfYears; 
	cin >> numberOfYears;
	
	totalInterest = yearlyInterest * numberOfYears;
	cout << "Here are the results." << endl;
	cout << "Loan Amount: " << loanAmount<< endl;
	cout << "Interest Rate: " << yearlyInterest << endl;
	cout << "Number of Payments: " << numberOfPayments << endl;
	cout << "Monthly Payment: " << payment << endl;
	cout << "Total Interest Paid: " << totalInterest << endl;
}


int main()
{
	float loanAmount;
	float monthlyInterest;
	int numberOfYears;
	int numberOfPayments = 0;
	float payment;
	float yearlyInterest = 0;
	float totalInterest = 0;

	cout << "Welcome to input loan amount program." << endl;
	cout << "Please remember that negative loan amount terminates the program!!!" << endl;
	cout << "Please enter a loan amount: ";
	cin >> loanAmount;
	while (loanAmount < 0)
	{
		cout << "Thanks for your business. BYE! Hope to see you later.You will receive a customer satisfaction survey to your email address." << endl;
		break;
	}


	
	GetLoanAmt(loanAmount);
	GetRest(monthlyInterest, numberOfYears);
	GetInterest(monthlyInterest);
	DeterminePayment(loanAmount, monthlyInterest, numberOfPayments, payment);
	PrintResults(loanAmount, yearlyInterest, numberOfPayments,  payment, totalInterest);

	return 0;
}

Last edited on
Topic archived. No new replies allowed.