Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m stuck and this is what I have. #include <iostream> #include <cmath> #includ

ID: 2267957 • Letter: I

Question

I'm stuck and this is what I have.

#include <iostream>

#include <cmath>

#include <iomanip>

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;

char another = 'Y';

while (toupper(another) == 'Y')

{

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;

if (creditRate >= 1)

creditRate /= 100;

//end if

if (dealerRate >= 1)

dealerRate /= 100;

//call function to calculate payments

creditPayment = getPayment(carPrice - rebate,

creditRate / 12, term * 12);

dealerPayment = getPayment(carPrice,

dealerRate / 12, term * 12);

//display payments

cout << fixed << setprecision(2) << endl;

cout << "Credit union payment: $"

<< creditPayment << endl;

cout << "Dealer payment: $"

<< dealerPayment << endl;

if (creditPayment < dealerPayment)

cout << "Take the rebate and finance through the credit union.";

else if (creditPayment > dealerPayment)

cout << "Don't take the rebate. Finance through the dealer.";

else

cout << "You can fiance through the dealer or the credit union.";

//end if

cout << endl;

cout << "Calculate another set of payments (Y/N)?";

cin >> another;

another = toupper(another);

}//end while

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

19. In this exercise, you will modify the car payment program from Lab 9-2. If necessary, create a new project named Intermediate19 Project, and save it in the Cpp8Chap09 folder. Copy the instructions from the Lab9-2.cpp file into a source file named Intermediate19.cpp. (Alternatively, you can enter the instructions from Figure 9-34 into the Intermediate19.cpp file.) Change the filename in the first comment. Make the modifications listed in Figure 9-39. Test the program appropriately. 1. Before calculating a monthly payment, verify that the denominator in the periodio payment formula is not the number 0. If it is 0, the function should return the number-1 (the negative number 1). In addition to displaying the monthly payments, the program should also display the following two amounts: 2. The total amount the user will pay for the car if the loan is financed through the credit union. The total amount the user will pay for the car if the loan is financed through the car dealer a. b.

Explanation / Answer

#include <iostream>

#include <cmath>

#include <iomanip>

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;

char another = 'Y';

while (toupper(another) == 'Y')

{

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;

if (creditRate >= 1)

creditRate /= 100;

//end if

if (dealerRate >= 1)

dealerRate /= 100;

//call function to calculate payments

creditPayment = getPayment(carPrice - rebate,creditRate / 12, term * 12);

dealerPayment = getPayment(carPrice,dealerRate / 12, term * 12);

//display payments

cout << fixed << setprecision(2) << endl;

if(creditPayment!=0)

{

cout << "Credit union payment: $"<< creditPayment << endl;

cout << "Total amount you will pay to Credit Union for "<< term << " years is: $"<< creditPayment*term*12 << endl <<endl;

}

else

return 0;

if(dealerPayment!=0)

{

cout << "Dealer payment: $"<< dealerPayment << endl;

cout << "Total amount you will pay to dealer for "<<term << " years is: $"<<dealerPayment*term*12 << endl <<endl;

}

else

return 0;

if (creditPayment < dealerPayment)

cout << "Take the rebate and finance through the credit union.";

else if (creditPayment > dealerPayment)

cout << "Don't take the rebate. Finance through the dealer." ;

else

cout << "You can fiance through the dealer or the credit union.";

//end if

cout << endl;

cout << "Calculate another set of payments (Y/N)?";

cin >> another;

another = toupper(another);

}//end while

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,denominator;

denominator=1 - pow(monthRate + 1, -months);

if(denominator==0)

{

cout << "Error"<<-1<<endl;

return 0;

}

else{

monthPay = prin * monthRate /denominator;

return monthPay;

}

}//end of getPayment function

Output:

Car price (after any trade-in): 20000
Rebate: 15000
Credit union rate: 10
Dealer rate: 8
Term in years: 12

Credit union payment: $59.75
Total amount you will pay to Credit Union for 12 years is: $8604.56

Dealer payment: $216.49
Total amount you will pay to dealer for 12 years is: $31174.63

Take the rebate and finance through the credit union.