-
-
Save anonymous/6af63249af34ad37dea3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include <cstdlib> | |
using namespace std; | |
//Prototypes | |
void printHead(); | |
void calcPieces(); | |
float loanAmt = 0; //Total Loan Amount | |
double intRate = 0; //Interest Rate as xx.xxx% | |
float pAmt = 0; //Payment Amount | |
int pNum = 1; //Payment Number counter | |
float tPrincipal; //Total Principal | |
float tInterest; //Total Interest | |
double principal; //Current principal | |
double interest; //Current interest | |
float balance; //Present Value of loan | |
int main() { | |
//Collect Information | |
while (loanAmt <= 0){ | |
cout << "Please input loan amount: "; | |
cin >> loanAmt; | |
if (loanAmt <= 0){cout << "Invalid amount entered, please enter another one: ";} | |
} | |
while (intRate <= 0){ | |
cout << "Please input interest rate as xx.xxx%: "; | |
cin >> intRate; | |
if (intRate <= 0){cout << "Invalid amount entered, please enter another one: ";} | |
intRate = intRate / 100; | |
} | |
while (pAmt <= 0){ | |
cout << "Please input monthly payment amount: "; | |
cin >> pAmt; | |
if (pAmt <= 0){cout << "Invalid amount entered, please enter another one: ";} | |
} | |
balance = loanAmt; | |
interest = 0.000; | |
//This needs to be the error check | |
while (balance > 0.00){ | |
printHead(); | |
while(pAmt <= balance){ | |
calcPieces(); | |
if (pNum%20 == 1){ | |
system("pause"); | |
printHead(); | |
} | |
} | |
calcPieces(); | |
balance = 0; | |
system("pause"); | |
} | |
return 0; | |
} | |
void printHead(){ | |
cout << "PAMT # PAMT AMT PRINCIPAL INTEREST BALANCE TTL INT TTL PRIN" << endl; | |
cout << "==============================================================================" << endl; | |
} | |
void calcPieces(){ | |
//Calc Interest and Principal, add to the totals, also balance | |
interest = balance * (intRate/12); | |
principal = pAmt - interest; | |
tInterest = tInterest + interest; | |
tPrincipal = tPrincipal + principal; | |
balance = balance - (pAmt - interest); | |
cout << setprecision(2) << fixed; | |
cout << std::right; | |
cout << std::setw(5); | |
cout << pNum; | |
cout << std::right; | |
cout << setw(9); | |
cout << pAmt; | |
cout << std::right; | |
cout << setw(14); | |
cout << principal; | |
cout << std::right; | |
cout << setw(14); | |
cout << interest; | |
cout << std::right; | |
cout << setw(14); | |
cout << balance; | |
cout << std::right; | |
cout << setw(10); | |
cout << tInterest; | |
cout << std::right; | |
cout << setw(14); | |
cout << tPrincipal << endl; | |
pNum++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment