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.
#include <iostream>
usingnamespace 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?
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.
@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);?