This is going to be somewhat of a long read, please bare with me.

First of all, these are the instructions to the program I'm supposed to make:
 ``12345678910111213141516171819202122232425262728`` ``````You will need a few things from the user. You should ask for the price per sq. foot. You should also ask for the dimensions of the house (length and width). You must then ask the user for a down payment percentage. The down payment must be at least 20%, if it's not, reject the input and ask the user to enter something a little higher (otherwise it would take forever to payoff)! Here are the functions I want: void SetupConsole(void); void GetUserInformation(void); int CalcSqFt(int nWidth, int nLength); double CalcDownPayment(double dDownPercent, int dSqFt, double dPricePerSqFt); void DisplayResult(double dDownPayment); SetupConsole will force the console to display the down payment in normal currency form (i.e. showing exactly two digits after the decimal point). GetUserInformation should ask the user for all the necessary details to calculate the down payment including the length and height of the house. Note that you will have to use global variables to store the user information!   CalcSqFt should calculate the total square footage for the house. CalcDownPayment should take the down payment percentage, the square footage, and the price per square foot.  CalcDownPayment will then return the amount needed for the down payment. DisplayResult should take the down payment and display it to the user. ``````

And so far, this is what my code looks like:

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253`` ``````#include using namespace std; void SetupConsole(void); void GetUserInformation(void); int CalcSqFt(int nWidth, int nLength); double CalcDownPayment(double dDownPercent, int dSqFt, double dPricePerSqFt); void DisplayResult(double dDownPayment); double dPricePerSqFt; int nWidth; int nLength; double dDownPercent; int main() { SetupConsole(void); GetUserInformation(void); CalcSqFt(nWidth, nLength); cout << CalcSqFt << endl; return 0; } void SetupConsole(void) { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); } void GetUserInformation(void) { cout << "Hello, enter the price (in \$) per sq foot: " << endl; cin >> dPricePerSqFt; cout << "Enter the width and length: " << endl; cin >> nWidth >> nLength; cout << "Enter the down payment percentage: " << endl; cin >> dDownPercent; } int CalcSqFt(int nWidth, int nLength) { return(nWidth * nLength); } double CalcDownPayment(double dDownPercent, int dSqFt, double dPricePerSqFt) { return(dDownPercent * dSqFt * dPricePerSqFt); }``````

However, I have a couple of problems/questions:
(1) When I call the CalcSqFt function to display to me the nWidth x nLength, I always get an output value of 1 and I have no idea why.
(2) If you look closely at the functions I'm to use, you'll notice that CalcSqFt is supposed to be dSqFt and dDownPayment is supposed to be CalcDownPayment. How do I make them equal each other?
Last edited on
Since you are calling all the functions from the main function, all the variables, include ing `nWidth` and `nLength` should first be declared in the main function, not as global variables.

Then pass them by reference to `GetUserInformation( &nWidth, &nLength)`, like so.

Then `CAlcSqFt` will return the value.

Also, if there are no parameters for a function, you do not need to put `(void)`, just `()`

Another thing, in your function prototypes, you do not need to put the variable names as the parameters. You only need to put the type. For example, `CalcDownPayment(double, int, double)`. This is because functions can be called with more than one set of variables.

And make sure that the parameters listed in the prototypes match the function definitions.
Your problem here is in these two lines:

 ``123`` ``````CalcSqFt(nWidth, nLength); cout << CalcSqFt << endl;``````

These should be abbreviated into a single call:

`cout << CalcSqFt(nWidth, nLength) << endl;`

The whole idea of a function is to use a function call as if it were a variable.

Xen
@TheJJJunk: thank you for the tips. However, as I'm just following the guidelines my professor has set out for us, I don't really want to mess with them just yet.

@Xenphibian, thank you! That did the trick.

However, I now have another problem. In the function `double CalcDownPayment(double dDownPercent, int dSqFt, double dPricePerSqFt);`, dSqFt should have the value of `int CalcSqFt(int nWidth, int nLength);`. How do I make it so?
I'm not sure if I'm making myself clear, so I'm going to try to phrase this again: how do I make the value of `dSqFt` from the function `ouble CalcDownPayment(double dDownPercent, int dSqFt, double dPricePerSqFt);` equal to the value of the function `int CalcSqFt(int nWidth, int nLength);`?
This is what I'm doing to try and make them the same:
`int dSqFt = CalcSqFt(nWidth, nLength);`

However, when I double check on the console for the answer to be the same, following this code:
 ``12`` ``````cout << CalcSqFt(nWidth, nLength) << endl; cout << dSqFt << endl;``````

I'll get the proper answer for the 1st cout, but the 2nd cout will always be 0. Help?
I have everything figured out, except how to make `void DisplayResult(double dDownPayment);` show the user what his down payment should be.

Here's the final code, with that bit of a problem:
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970`` ``````#include using namespace std; void SetupConsole(void); void GetUserInformation(void); int CalcSqFt(int nWidth, int nLength); double CalcDownPayment(double dDownPercent, int dSqFt, double dPricePerSqFt); void DisplayResult(double dDownPayment); double dPricePerSqFt; double dDownPercent; int nWidth; int nLength; int main() { SetupConsole(); GetUserInformation(); CalcSqFt(nWidth, nLength); int dSqFt = CalcSqFt(nWidth, nLength); CalcDownPayment(dDownPercent, dSqFt, dPricePerSqFt); double dDownPayment = CalcDownPayment(dDownPercent, dSqFt, dPricePerSqFt); cout << "Okay, you will need " << DisplayResult << " to place for a down payment" << endl; } void SetupConsole(void) { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); } void GetUserInformation(void) { cout << "Hello, enter the price (in \$) per sq foot: " << endl; cin >> dPricePerSqFt; cout << "Enter the width and length: " << endl; cin >> nWidth >> nLength; cout << "Enter the down payment percentage: " << endl; cin >> dDownPercent; while (dDownPercent < 20) { cout << "Oops, that's too small! Enter something bigger: " << endl; cin >> dDownPercent; } if (dDownPercent >= 20) { return; } } int CalcSqFt(int nWidth, int nLength) { return(nWidth * nLength); } double CalcDownPayment(double dDownPercent, int dSqFt, double dPricePerSqFt) { return((dSqFt * dPricePerSqFt * dDownPercent) / 100); } void DisplayResult(double dDownPayment) { return(dDownPayment); }``````
Nevermind, figured it out.

For those of you who are curious as to what the final product looks like:

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970`` ``````#include using namespace std; void SetupConsole(void); void GetUserInformation(void); int CalcSqFt(int nWidth, int nLength); double CalcDownPayment(double dDownPercent, int dSqFt, double dPricePerSqFt); void DisplayResult(double dDownPayment); double dPricePerSqFt; double dDownPercent; int nWidth; int nLength; int main() { SetupConsole(); GetUserInformation(); CalcSqFt(nWidth, nLength); int dSqFt = CalcSqFt(nWidth, nLength); CalcDownPayment(dDownPercent, dSqFt, dPricePerSqFt); double dDownPayment = CalcDownPayment(dDownPercent, dSqFt, dPricePerSqFt); DisplayResult(dDownPayment); } void SetupConsole(void) { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); } void GetUserInformation(void) { cout << "Hello, enter the price (in \$) per sq foot: " << endl; cin >> dPricePerSqFt; cout << "Enter the width and length: " << endl; cin >> nWidth >> nLength; cout << "Enter the down payment percentage: " << endl; cin >> dDownPercent; while (dDownPercent < 20) { cout << "Oops, that's too small! Enter something bigger: " << endl; cin >> dDownPercent; } if (dDownPercent >= 20) { return; } } int CalcSqFt(int nWidth, int nLength) { return(nWidth * nLength); } double CalcDownPayment(double dDownPercent, int dSqFt, double dPricePerSqFt) { return((dSqFt * dPricePerSqFt * dDownPercent) / 100); } void DisplayResult(double dDownPayment) { cout << "Okay, you will need " << dDownPayment << " to place for a down payment" << endl; }``````
Topic archived. No new replies allowed.