#include <iostream>
#include <iomanip>
#include <cmath>
using std::cout;
using std::cin;
using std::endl;
using std::fixed;
using std::setprecision;
//fucntion prototype
void calcPayment (double,double, int);(what I changed)
//double calcPayment (double, double, int);(what I originally had)
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
cout << fixed << setprecision(2) << endl;
cout << "Credit union payment: $" << creditPayment << endl;
cout << "Dealer payment: $" << dealerPayment << endl;
return 0;
}//end of main function
//*****function definitions*****
void calcPayment (double prin, double monthRate, int months) (what I changed)
//double calcPayment(double prin, double monthRate, int months) (what I originally had)
{
//calculates and returns a monthly payment
double monthPay=0.0;
monthPay=prin*monthRate/(1-pow(monthRate + 1, -months));
return monthPay;
}//end of calcPayment function
Void function help please
Started by hoku2000_99, Mar 13 2009 08:27 PM
1 reply to this topic
#1
Posted 13 March 2009 - 08:27 PM
I have to modify this program so that it uses a void function, rather than a value-returning function, to calculate the monthly payments. I started where I have my function prototype, but not too sure what to change or where to go next in this program.
|
|
|
#2
Posted 14 March 2009 - 05:12 AM
Add a parameter to your function so it accepts the output variable as a reference to the original variable. You will need to use a reference or a pointer in your function to pass back the result.


Sign In
Create Account


Back to top









