Quote
Car Price : 16000
Rebate : 3000
Credit Union Rate : .08
Dealer Rate : .03
Term In Years : 4
Credit Union Payment : $ 0.08
Dealer Payment : $ 0.03
Monthly Payment: $00411163
Press any key to continue . . .
Rebate : 3000
Credit Union Rate : .08
Dealer Rate : .03
Term In Years : 4
Credit Union Payment : $ 0.08
Dealer Payment : $ 0.03
Monthly Payment: $00411163
Press any key to continue . . .
To test the code use the following:
Car Price - 16000
Rebate - 3000
Credit Union Rate - .08
Dealer Rate - .03
Term - 4
Thanks for any direction you can give me. I am trying very hard to absorb C++
#include <iostream>
#include <iomanip>
#include <cmath>
using std::cout;
using std::cin;
using std::endl;
using std::fixed;
using std::setprecision;
//function prototype
double calcPayment (double, double, int);
void displayPayment (double, double);
int main ()
{
// declare variables
double carPrice = 0.0;
double rebate = 0.0;
double creditRate = 0.0;
double dealerRate = 0.0;
int term = 0;
double creditPayment = 0.0;
double dealerPayment = 0.0;
// Get input items
cout << "Car Price : ";
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 = calcPayment (carPrice - rebate, creditRate / 12, term * 12);
dealerPayment = calcPayment (carPrice, dealerRate / 12, term * 12);
// Display Payments
displayPayment (creditRate, dealerRate);
return 0;
// End of main function
}
// ***** Function Definitions *****
double calcPayment ( double prin, double monthRate, int months )
{
// Calculates and returns a month payment
double monthPay = 0.0;
monthPay = prin * monthRate / ( 1 - pow(monthRate + 1, -months));
return monthPay;
//end of calcPayment function
}
void displayPayment (double creditPayment, double dealerPayment)
{
cout << fixed << setprecision (2) << endl;
cout << "Credit Union Payment : $ " << creditPayment << endl;
cout << "Dealer Payment : $ " << dealerPayment << endl;
cout << "Monthly Payment: $" << calcPayment << endl;
}
// end of displayPayment function
This post has been edited by greenbluekidz: 21 January 2009 - 04:24 PM

New Topic/Question
Reply




MultiQuote



|