Question: I'm having issues getting a valid # once I put in the required data. I put in simple #s to calculate and I get insane

I'm having issues getting a valid # once I put in the required data. I put in simple #s to calculate and I get insane number amounts and I can't figure out where I went wrong. Here is the question:

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 Cpp8\Chap09 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 periodic payment formula is not the number 0. If it is 0, the function should return the number 1 (the negative number 1). 2. In addition to displaying the monthly payments, the program should also display the following two amounts: a. The total amount the user will pay for the car if the loan is financed through the credit union. b. The total amount the user will pay for the car if the loan is financed through the car dealer.

Here is my code:

#include #include #include using namespace std; //function prototypes double getPayment(int, double, int); int main() { int carPrice = 0; int rebate = 0; int term = 0; double creditRate = 0.0; double dealerRate = 0.0; double dealerPayment = 0.0; double creditPayment = 0.0; double dealerTotal = 0.0; double unionTotal = 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 functions to calculate payments creditPayment = getPayment(carPrice - rebate, creditRate / 12, term * 12); dealerPayment = getPayment(carPrice, dealerRate / 12, term * 12); unionTotal = creditPayment * (term * 12); dealerTotal = dealerPayment * (term * 12); //display payments cout << fixed << setprecision(2) << endl; cout << "Credit Union payment: $" << creditPayment << endl; cout << "Credit Union total amount: $" << unionTotal << endl; cout << "Dealer payment: $" << dealerPayment << endl; cout << "Dealer total amount: $" << dealerTotal << 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; if (prin > 0 && (1 - pow(monthRate + 1, -months)) < 0) return -1; else { monthPay = prin * monthRate / (1 - pow(monthRate + 1, -months)); return monthPay; } } //end of getPayment function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!