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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
bool YorN();
double InputValidate(string);
//ResultDisplay();
//OutputSnow();
//OutputAva();
//SortBal();
//Rollover();
//CalcInt();
//CalcPayoff();
void SortRates( string[][2], double[][2], double[][2], double[][2], int);
int GetData( string[][2], double[][2], double[][2], double[][2] );
//void Welcome();
int main() {
system("cls");
int size;
int months[2];
string names[20][2];
double balance[20][2], rates[20][2], pymnts[20][2], inAccru[20][2], inTotal[2];
//Welcome();
size = GetData( names, balance, rates, pymnts );
SortRates( names, balance, rates, pymnts, size );
}
int GetData( string names[][2], double balance[][2], double rates[][2], double pymnts[][2] ) {
string input;
int count = 0;
bool more = true;
while (more) {
count++;
cout << " Please enter a name for your loan.\n\n ";
getline( cin, names[count][0] );
system("cls");
cout << " Please enter the principal balance.\n\n "
<< names[count][0] << "\n $";
getline(cin, input);
balance[count][0] = InputValidate(input);
system("cls");
cout << " Please enter the interest rate. Example 4.5,"
<< "enter 0 for zero.\n\n " << names[count][0] << "\n $"
<< balance[count][0] << "\n ";
getline(cin, input);
rates[count][0] = InputValidate(input);
system("cls");
cout << " Please enter the minimum monthly payment.\n\n "
<< names[count][0] << "\n $" << balance[count][0] << "\n "
<< rates[count][0] << "%\n $";
getline(cin, input);
pymnts[count][0] = InputValidate(input);
system("cls");
cout << "\n\n " << names[count][0] << "\n $" << balance[count][0]
<< "\n " << rates[count][0] << "%\n $" << pymnts[count][0];
cout << "\n\n Do you have another to add? (y/n): ";
more = YorN();
cin.clear();
cin.ignore();
}
return count;
}
double InputValidate(string sInput) {
double num = 0;
bool again = true;
while (again) {
system("cls");
stringstream(sInput) >> num;
if ( !isdigit(sInput[0]) ) {
cout << "\n Please enter a number. \n";
getline(cin, sInput);
} else if ( num < 0 ) {
cout << "\n Please enter a positive number. \n";
getline(cin, sInput);
} else {
again = false;
}
}
return num;
}
bool YorN() {
char answer;
bool again = true;
while(again) {
cin >> answer;
system("cls");
answer = tolower(answer);
if (answer == 'y') {
again = true;
break;
} else if (answer == 'n') {
again = false;
break;
} else {
cout << "Please enter (y/n). Do you have another? ";
}
}return again;
}
void SortRates( string names[][2], double balance[][2], double rates[][2], double pymnts[][2], int size) {
int index, scan, row = 0;
string unNm;
double unBal, unRt, unPy;
for (index = 1; index < size; index++) {
unRt = rates[index][0];
unNm = names[index][0];
unBal = balance[index][0];
unPy = pymnts[index][0];
scan = index;
while (scan > 0 && rates[scan-1][0] < unRt) {
rates[scan][0] = rates[scan - 1][0];
names[scan][0] = names[scan - 1][0];
balance[scan][0] = balance[scan - 1][0];
pymnts[scan][0] = pymnts[scan - 1][0];
--scan;
}
rates[scan][0] = unRt;
names[scan][0] = unNm;
balance[scan][0] = unBal;
pymnts[scan][0] = unPy;
}
//CalcPayoff(row);
}
|