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;
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;
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);
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.
#include <iostream>
usingnamespace 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 :)