/* face-value calculator for 1711B 98/9/23 To calculate the face value of a consumer loan. Method use the formula: face_value = received / (1.0 - i_rate*(loan_time/12.0)); where received is received by the consumer i_rate is the interest rate (%) and loan_time is the duration in months. */ #include const int dollar = 2; int main() { double i_rate_percent, i_rate, face_value, received, // by consumer payment; //monthly int loan_time; // in months char response; do { //get inputs cout << "Type in the loan amount required (decimal number), \n"; cout << "the interest rate (%), and the duration in months>" << endl; cin >> received >> i_rate_percent >> loan_time; //trap input errors if (( received > 0.0 ) && (i_rate_percent > 0.0) && (loan_time > 0)) { // calculate i_rate = i_rate_percent / 100.0; face_value = received / (1.0 - i_rate*(loan_time/12.0)); payment = face_value/loan_time; // echo inputs and report cout << endl <<"For a loan of $" << received << endl; cout <<" over " << loan_time << " months" << endl; cout <<" at a rate of " << i_rate_percent << "percent\n" << endl; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(dollar); cout <<"the total borrowed is $" << face_value << endl; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(dollar); cout <<"the monthly payment is $" << payment << endl << endl; } else cout << "Invalid entry: all values must be positive" << endl << endl; cout << "If you want to try again input Y, otherwise input N" << endl; cin >> response; } while ((response == 'Y')||(response == 'y'); // allows lower-case y response return 0; }