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

int main() {
	// input variables
    double Cost, Cash, APR;
	int term;

    // First, note the cost of the car (Cost),
    cout << "Enter the cost of the car: $";
	cin >> Cost;

    // the amount of money you have saved (Cash),
    cout << "Enter the amount of money you saved: $";
	cin >> Cash;

    // and the sales tax rate (TaxRate) (6% e.g.)
    double SalesTaxRate = 6.0;

    // Also, note the financials: the interest rate (APR),
    // and the term of the loan (Term)
    // The interest rate quoted is generally the annual
    // percentage rate (APR)
    cout << "Enter the APR for the loan (in %): ";
	cin >> APR;

    // Input the term of the loan (Term)
    cout << "Enter length of loan term (in months): ";
	cin >> term;

    // Convert it (APR) to monthly rate (divide it by 12) (MR)
    // also divide it by 100 since the value input is in %
    double MR = APR/12.0/100.0;

    // Next, compute the sales tax you will pay (SalesTax)
    double SalesTax = Cost * SalesTaxRate / 100.0;

    // Use the money left to make a down payment (DownPayment)
    double DownPayment = Cash - SalesTax;

    // Then determine the amount you will borrow (LoanAmount)
    double LoanAmount = Cost - DownPayment;

    // Plug in all of the values in the formula and compute
    // the monthly payment (MP)
    double MP = (LoanAmount * MR) / (1.0 - exp(-term * log(1.0+MR)));

    // Also, compute the total cost of the car. (TotalCost)
    double TotalCost = SalesTax + DownPayment + MP * term;

    // Output all the results
    printf ("Here are the details about your new car...\n");
    printf ("------------------------------------------\n");
    printf ("\n");
    printf ("Money you have saved $%1.2f\n", Cash);
    printf ("Cost of the car $%1.2f\n", Cost);
    printf ("Sales Tax rate is %1.2f%%\n", SalesTaxRate);
    printf ("Sales Tax on the car $%1.2f\n", SalesTax);
    printf ("Your down payment will be $%1.2f\n", DownPayment);
    printf ("You will be borrowing $%1.2f\n", LoanAmount);
    printf ("A %2d month loan at %1.2f%% APR\n", term, APR);
    printf ("Your monthly payment will be $%1.2f\n", MP);
    printf ("Total cost will be $%1.2f\n", TotalCost);
    printf ("\n");
    return 0;
}

