trouble with mortgage calculater program

Hi I am trying to write a program that computes monthly interest, monthly bill and new balance. The problem is that In one of the functions I am using the variable isn't initializing. I'm sure its a simple fix but i can't see it. Don't pay attenttion to the actual formulas because their not right because I wont to fix the syntax before. the problem is the monthly_payment function

#include <iostream>
#include <cmath>
using namespace std;

void get_input(double principal1, double rate1, double length1);
void conversions(double& monthly_interest1, double& months1);
double monthly_paymentF(double monthly_payment1);
void monthly_amounts(double& m_interest_payment1, double new_principal1);
void print_payment_table(double m_interst_payment1, double m_principal_amount1, double new_principal1);
void print_header();

int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

void get_input(double& principal1, double& annual_rate1, double& length_years1); //function call for input function
void conversions(double& monthly_interest1, double& months1); //function call for conversions
void monthly_amounts(double m_interest_payment1, double new_principal1); //function call for monthly amounts
double monthly_paymentF(double monthly_payment1); // monthly payment call
void print_payment_table(double m_interst_payment1, double m_principal_amount1, double new_principal1);
}
void get_input(double& principal1, double& annual_rate1, double& length_years1) //function definintion to get input from the user.
{
double principal, annual_rate, length_years;

cout << "Please enter the principal: ";
cin >> principal; cout <<endl;
cout << "please enter the annual interest rate: ";
cin >> annual_rate; cout <<endl;
cout << "Please enter the length of the loan in years: ";
cin >> length_years; cout <<endl;
}

void conversions(double& monthly_interest1, double& months1) //function definition to convert annual rate and length into monthly increments
{
double monthly_rate_decimal, length_years, length_months, annual_rate;

monthly_rate_decimal = annual_rate / (12 * 100);
length_months = (length_years * 12);
cout << monthly_rate_decimal;
cout <<endl;
cout <<endl;
}

double monthly_paymentF(double monthly_payment1) //function definition to calculate the monthly payment
{
double principal, monthly_rate_decimal, m_principal_amount;

m_principal_amount = (principal * (monthly_rate_decimal)) / (1 - (1 + monthly_rate_decimal)));
return m_principal_amount; This is the variable that isn't initializing
void print_header() // function call for table header
}

void monthly_amounts(double& m_interest_payment1, double new_principal1) //function definition to calculate monthly interest payment and new principal
{
double principal, new_principal, m_principal_amount, m_interest_rate, monthly_rate_decimal;

m_interest_rate = principal * monthly_rate_decimal;

do
new_principal = principal - (m_principal_amount);

while(new_principal >= 0);

}

void print_payment_table(double m_interst_payment1, double m_principal_amount1, double new_principal1) //function definition to print the monthly interest payment and monthly principal payment
{
double m_interest_rate, m_principal_amount, new_principal;
cout << m_interest_rate; cout <<endl;
cout <<"/t"; cout <<"/t"; cout <<"/t";
cout << m_principal_amount; cout <<endl;
cout <<"/t"; cout <<"/t"; cout <<"/t";
cout << new_principal; cout <<endl;
cout <<"/t"; cout <<"/t"; cout <<"/t";
}

void print_header()
{
cout <<"/t";
cout << "Table of Mortgage payments"; cout <<endl;
}
closed account (3hM2Nwbp)
Divide and conquer - attacking that program's syntax all at once would be a bit confusing. Break your syntax fixing down into smaller sections - like each individual method. You can use this as a general guide as to what your issue is.

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
#include <iostream>
using namespace std;

int main()
{
	double principal, annual_rate, length_years;		//Variables for holding the data from the function call
	get_input(principal, annual_rate, length_years);	//Call our input gathering method
	//Here, principal, annual_rate, length_years have been changed, since we passed references of them to the get_input method
}

/* This style of documentation is stolen from Java - I think the standardized documentation style is professional.
 *
 *	@Name
 *		get_input
 *
 *	@Purpose
 *		To collect user-input for mortgage calculation
 *
 *	@param principal
 *		A reference to a double representing the principal of the mortgage.
 *		Anything we do to this parameter will happen to the variable we pass into this method
 *
 *	@param annual_rate
 *		A reference to a double representing the annual rate of the mortgage.
 *		Anything we do to this parameter will happen to the variable we pass into this method
 *
 *	@param length_years
 *		A reference to a double representing the length of the mortgage, in years
 *		Anything we do to this parameter will happen to the variable we pass into this method
 *
 *	@return void
 *		The arguments are passed in by reference, so the changes to them are reflected in the variables passed to this method.
 */

void get_input(double& principal, double& annual_rate, double& length_years)
{
	cout << "Please enter the principal: ";
	cin >> principal; cout <<endl;
	cout << "please enter the annual interest rate: ";
	cin >> annual_rate; cout <<endl;
	cout << "Please enter the length of the loan in years: ";
	cin >> length_years; cout <<endl;
}


Code can be self-documenting, but it never hurts to throw some more in :)
Last edited on
Topic archived. No new replies allowed.