For a function protoype header can one be double while the other one is void? I'm trying to make the void displayPayment function work, but am a little lost. Should I turn the carPrice, Rebate, ect.. into void functions in the prototype, or can they work without doing that? Thanks for your time, Michelle

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
//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

	cout << fixed << setprecision(2) << endl;
	cout << "Credit union payment: $"
		<<creditPayment << endl;
	cout << "Dealer payment: $"
		<< dealerPayment << endl;
	return 0;
}   //end of main function

//*****function definitions*****
double calcPayment(double 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;
void displayPayment (double monthPay)
	cout << "Monthly Payment: "<< monthPay << endl;

//end of calcPayment function

Your prototype and your definition should always match EXACTLY, that is true for functions and everything else.
Since the point of the prototype is to tell the rest of the code exactly how the function, that is defined later, should be called, so it is meaningless if the definition does not meet the prototype in terms of number of arguments, their types and qualifiers, and the return type (and also the calling convention and any other function qualifiers).

two exceptions:
1. The parameter names in the prototype are not necessary or required to match the definition, but the types and number of argument must match exactly, including the return type.
2. If you have a default parameter value in the prototype, it should not appear in the definition.

there are a few other differences with function templates, but that will be a bit further down your learning process.

So for all that matters, PROTOTYPE == DEFINITION

so in the above code, the definition of displayPayment must be:

void displayPayment (double monthPay, double& whateverVariableNameHERE)
{ .. }

to match its prototype.

PS: please put your code between tags, for readability.

Change void displayPayment (double, double&); to void displayPayment (double);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.