Hello everyone! This is my first forum post, and I am looking for help with finding principal, and interest on a loan. In addition I am suppose to have a third function that is suppose to print the data from the calculating function. Any help would be welcomed. :)
Here is my code:
#include <iostream>
#include <iomanip>
using namespace std;
void getfunction(double &dollarbalance, double &interestrate, double &paymentpermonth);//function protoypes, shows how data will be passed
void calcSchedule();//function prototypes
void getfunction(double &dollarbalance, double &interestrate, double &paymentpermonth)//function that shows how data that will be entered will be passed to the next function
{
cout << "Enter the balance of your loan to be paid off: $";//output
cin >> dollarbalance;//input
cout << "Enter the interest rate (compounded monthly) : ";//output
cin >> interestrate;//input
cout << "Enter your monthly payment : $";//output
cin >> paymentpermonth;//input
}
void calcSchedule()//function
{
getfunction(dollarbalance, interestrate, paymentpermonth);//calls the previous functions data
cout.setf(ios::fixed); //set precision for output to be two decimal places
cout.setf(ios::showpoint);//set precision for output to be two decimal places
cout.precision(2); //set precision for output to be two decimal places
startingbalanceOnloan = dollarbalance;//sets the starting balance equal to the dollarbalance to allow it to be calculated
while (interestrate >= 1) //while statement that is suppose to calculate interestrate
{
interestrate = interestrate / 100; //expression to calculate interestrate
}
dollarbalance = dollarbalance * (1 + interestrate / 12) - paymentpermonth;//how the remaining balance will be calculated
cout << "After your first payent your balance is $" << dollarbalance <<endl;//informing user after first payment
cout<<setw(10)<<"Payment"<<setw(10)<<"Balance"<<setw(10)<<"Interest"<<setw(10)<<"Principle"<<endl;//output to display data with spaces
while (dollarbalance > 0)//while statement showing that dollar balance is greater than 0 then do this
{
if (dollarbalance < paymentpermonth)//if statement that say if the dollarbalance is less than the payment per month then subtract the dollar balance
{
dollarbalance = dollarbalance - dollarbalance;//expression for calculating
}
else //else statement that says to do this if the above is not true
{
dollarbalance = dollarbalance * (1 + interestrate / 12) - paymentpermonth;//this still calculates dollarbalance
}
if(dollarbalance>-1)//if statement that displays the number of payments in increasing order
{
months++;//add months to show the number of payments until balance is 0
}
cout <<setw(10)<< months <<setw(10)<< dollarbalance<<setw(10)<<interestrate<<setw(10)<<principal<<endl;//displays output with 10 spaces to line up data
}
interestThatIsPaid = (paymentpermonth * interestrate)+paymentpermonth;//suppose to calculate total interest rate
cout << "You paid a total ammount of $" << interestThatIsPaid << " in intrest." << endl;//informs user of interest
cout <<" The loan is paid off. You no longer owe any money" << endl;//informs user the debt is paid off