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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#include <iostream> // For cin and cout functions
#include <cmath> // For exp function
#include <string> // For string expressions in descriptions/directions
#include <iomanip> // For setprecision function
using namespace std;
// Function prototypes
float getPrice (float);
float getTradeIn (float, float);
float getDownPayment (float, float, float);
float getInterestRate (float);
float calcMonPayment ();
float displayLoanSchedule();
int main ()
{
float price;
float tradeIn;
float downPayment;
float annualIntRate;
//************************************************************************************************************
// This section will walk the user through the general purpose of this application and will walk
// them through inputting the data into the system for calculations.
cout << " This program is design to help you calculate the monthly car" << endl;
cout << " payment(s) for a single customer, or multiple different customers." << endl << endl;
cout << " To begin, you will be asked a series of questions to gather the information" << endl;
cout << " needed in the calculations." << endl << endl;
cout << "Please put in the total price of the vehicle(between $50.00 and $50,000.00: $";
price = getPrice(price);
cout << price;
cout << "Please put in the trade in value (greater than or equal to 0, but less than price of car";
tradeIn = getTradeIn(tradeIn, price);
cout << tradeIn;
cout << "Please put in the down payment value (greater than or equal to 0, but less than" << endl;
cout << "the price minus the trade in value)";
downPayment = getDownPayment(downPayment, price, tradeIn);
cout << downPayment;
cout << "Please put in the annual interest rate as a decimal (8% = 0.08). This can't be greater" << endl;
cout << "than 19% (or 0.19)";
annualIntRate = getInterestRate(annualIntRate);
cout << annualIntRate;
}
/****************************************************************************
* This section will list all functions to be used throughout the program. *
****************************************************************************/
float getPrice (float price)
{
do
{
cin >> price;
}
while (price > 75 && price >= 48500);
return getPrice(price);
}
float getTradeIn (float tradeIn, float price)
{
do
{
cin >> tradeIn;
}
while (tradeIn >= 0 && tradeIn < price);
return getTradeIn(tradeIn, price);
}
float getDownPayment (float downPayment, float price, float tradeIn)
{
do
{
cin >> downPayment;
}
while (downPayment >= 0 && downPayment < ((price) - (tradeIn)));
return getDownPayment(downPayment, price, tradeIn);
}
float getInterestRate (float annualIntRate)
{
do
{
cin >> annualIntRate;
}
while (annualIntRate > 0 && annualIntRate <= 0.19);
return getInterestRate(annualIntRate);
}
float calcMonPayment(float annualIntRate, float price, float downPayment, float tradeIn, float monPayment[5], float monIntRate, float annualIntPercent, float loanAmt)
{
monIntRate = annualIntRate / 12.0;
annualIntPercent = annualIntRate * 100.0;
loanAmt = price - downPayment - tradeIn;
monPayment[0] = (loanAmt * monIntRate)/pow((1.0-(1+monIntRate)), -12);
monPayment[1] = (loanAmt * monIntRate)/pow((1.0-(1+monIntRate)), -24);
monPayment[2] = (loanAmt * monIntRate)/pow((1.0-(1+monIntRate)), -36);
monPayment[3] = (loanAmt * monIntRate)/pow((1.0-(1+monIntRate)), -48);
monPayment[4] = (loanAmt * monIntRate)/pow((1.0-(1+monIntRate)), -60);
}
float displayLoanSchedule (float price, float tradeIn, float downPayment, float loanAmt, float annualIntRate, float annualIntPercent, float monIntRate, int noMonths, float monPayment[5])
{
//************************************************************************************************************
// This section will provide the format for the payment information chart.
cout << "Honest Dave's Used Cars" << endl << endl;
cout << "Vehicle price: $" << fixed << setprecision(2) << price << endl;
cout << "Trade-In Value: $" << fixed << setprecision(2) << tradeIn << endl;
cout << "Down Payment: $" << fixed << setprecision(2) << downPayment << endl;
cout << "-------------------------------" << endl;
cout << "Loan Amount: $" << fixed << setprecision(2) << loanAmt << endl << endl;
cout << "Annual Interest Rate: " << annualIntPercent << "%" << endl << endl;
cout << "Monthly Payments:" << endl;
cout << "12 Months " << monPayment[0] << endl;
cout << "24 Months " << monPayment[1] << endl;
cout << "36 Months " << monPayment[2] << endl;
cout << "48 Months " << monPayment[3] << endl;
cout << "60 Months " << monPayment[4] << endl;
}
| |