1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <iostream>
using namespace std;
void SetupConsole(void);
void GetUserInformation(double &dDownPercent, int &nWidth,
int &nLength, double &dPricePerSqFt);
int CalcSqFt(int nWidth, int nLength);
double CalcDownPayment(double dDownPercent, int dSqFt, double dPricePerSqFt);
void DisplayResult(double dDownPayment);
int main()
{
double dDownPercent;
int nWidth;
int nLength;
double dPricePerSqFt;
SetupConsole();
GetUserInformation(dDownPercent, nWidth, nLength, dPricePerSqFt);
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(double &dDownPercent, int &nWidth,
int &nLength, double &dPricePerSqFt)
{
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;
cout << " to place for a down payment." << endl;
}
|