So I have this C program that im supposed to modify Its a ca
So I have this C++ program that i\'m supposed to modify. It\'s a car buying program but i need it to do a few more things then what i have already.
1. before it can calculate a monthly payment i need it to verify that the denominator in the peridoc formula is not a 0 otherwise the function should return a -1.
2. besides displaying the monthly payments the program should also display two more things. the total amount paid if the user picks either one of the payment options (either the credit union or the dealer payment)
Here is what i have so far
#include <iostream>
#include <cmath>
#include <iomainip>
using namespace std;
//function prototype
double getPayment(int, double, int,);
int main()
{
int carPrice = 0;
int rebate = 0;
double creditRate = 0.0;
double dealerRate = 0.0;
int term = 0;
double creditPayment = 0.0;
double dealerPayment = 0.0;
cout << \"Car price (after any trade-in): \";
cin >> carPrice;
cout << \"Rebate: \";
cin >> rebate;
cout << \"Credit union rate: \";
cin >> creditRate;
cout << \"Dealer rate: \";
cin >> dealerRate;
cout << \"Term in years: \";
cin >> term;
//call function to calculate payments
creditPayment = getpayment(carPrice - rebate, creditRate / 12, term * 12);
dealerPayment = getPayment(carPrice - rebate, dealerRate / 12, term * 12);
//displays payments
cout << fixed << setprecision(2) << endl;
cout << \"Credit union payment: $\"
<< creditPayment << endl;
cout << \"Dealer payment: $\";
<< dealerPayment << endl;
system(\"pause\")
return 0;
}//end of main function
//*****function definitions*****
double getPAyment(int prin,
double monthRate,
int months)
{
//calculates and returns a monthly payment
double monthPay = 0.0;
monthPay = prin * monthRate /
(1 - pow(monthRate + 1, -months));
return monthPAy;
}//end of getPayment function
Any help is welcome!
Solution
Note:
Required changes done in the given code.
Solution:
#include <iostream>
#include <cmath>
//#include <iomainip>
using namespace std;
//function prototype
double getPayment(int, double, int);
int main()
{
int carPrice = 0;
int rebate = 0;
double creditRate = 0.0;
double dealerRate = 0.0;
int term = 0;
double creditPayment = 0.0;
double dealerPayment = 0.0;
double Tot_creditPayment = 0.0;
double Tot_dealerPayment = 0.0;
cout << \"Car price (after any trade-in): \";
cin >> carPrice;
cout << \"Rebate: \";
cin >> rebate;
cout << \"Credit union rate: \";
cin >> creditRate;
cout << \"Dealer rate: \";
cin >> dealerRate;
cout << \"Term in years: \";
cin >> term;
//call function to calculate payments
creditPayment = getPayment(carPrice - rebate, creditRate / 12, term * 12);
dealerPayment = getPayment(carPrice - rebate, dealerRate / 12, term * 12);
Tot_creditPayment = creditPayment * term * 12;
Tot_dealerPayment = dealerPayment * term * 12;
//displays payments
//cout << fixed << setprecision(2) << endl;
cout << \"Credit union payment: $\" << creditPayment << endl;
cout << \"Credit Total payment: $\" << Tot_creditPayment << endl;
cout << \"Dealer payment: $\" << dealerPayment << endl;
cout << \"Dealer Total payment: $\" << Tot_dealerPayment << endl;
system(\"pause\");
return 0;
}//end of main function
//*****function definitions*****
double getPayment(int prin, double monthRate, int months)
{
//calculates and returns a monthly payment
double monthPay = 0.0,deno;
deno= (1 - pow(monthRate + 1, -months));
if(deno==0)
monthPay =-1;
else
monthPay = prin * monthRate / deno;
return monthPay;
}//end of getPayment function
Result:
Car price (after any trade in): 10000
Rebate: 1000
Credit union rate: 11
Dealer rate: 10
Term in years: 5
Credit union payment: $8250
Credit Total payment: $495000
Dealer payment: $7500
Dealer Total payment: $450000



