#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
float price; //the price of the vehicle purchased
float downpayment; //the down payment on the loan
float tradein; //the amount of the trade in
float loanamt; //the amount of the loan
float annualintrate; //annual interest rate
float annualintpercent; //annual interest rate as a fraction
float monintrate; //monthly interest rate as a percent
int nomonths; //number of monthly payments
float monpayment; //monthly payment amount
monintrate = annualintrate / 12;
annualintpercent = annualintrate * 100;
loanamt = price - downpayment - tradein;
monpayment = (loanamt * monintrate) / (1.0 -(1 + monintrate) ^ -nomonths);
do //looping for the price to be between 50 and 50,000
{
cout << "please enter the price of the vehicle (between 50 and 50,000) :" << endl;
cin >> price;
} while (price < 50 || price > 50000);
do //looping for the tradin value
{
cout << "please enter the amount for the trade in vehicle:" << endl;
cin >> tradein;
} while (tradein >= 0 ||tradein < price);
do //looping for the downpayment amount
{
cout << "please enter the amount for the downpayment where the downpayment is less than the price minus the trade in value" << endl;
cin >> downpayment;
} while (downpayment >= 0 ||downpayment > price - tradein);
do //looping for the annual interest rate
{
cout << "enter the annual interest rate for the loan as a decimal (ie .4 for 40%)" << endl;
cin >> annualintrate;
} while (annualintrate >= 0 ||annualintrate > 50);
//Giving Back the Info!
cout << "Honest Dave's used cars" << endl;
cout << endl;
cout << "Vehicle price: " << price << endl;
cout << "Trade in value: " << tradein << endl;
cout << "Down Payment: " << downpayment << endl;
cout << " ----------" << endl;
cout << "Loan Amount: " << loanamt << endl;
cout << "Annual Interest Rate: " << annualintpercent << "%" << endl;
cout << endl;
cout << "Monthly Payment Options" << endl;
cout << endl;
{
nomonths = 24;
cout << "24 months: " << monpayment << endl;
}
{
nomonths = 36;
cout << "36 months: " << monpayment << endl;
}
{
nomonths = 48;
cout << "48 months: " << monpayment << endl;
}
{
nomonths = 60;
cout << "60 months: " << monpayment << endl;
}
return 0; //DONE!
}