Calculates a monthly loan payment by defining a custom function with the standard amortization formula, showcasing a practical, real-world use case.
ID: 1267
using uCalcSoftware;
var uc = new uCalc();
// Define a function for the standard loan payment formula
uc.DefineFunction("LoanPmt(rate, nper, pv) = Int((rate * pv) / (1 - (1 + rate)^-nper)*100)/100");
// Define variables for the calculation
uc.DefineVariable("monthly_rate = 0.05 / 12"); // 5% annual rate
uc.DefineVariable("periods = 30 * 12"); // 30 years
uc.DefineVariable("loan_amount = 200000"); // $200,000
Console.WriteLine(uc.EvalStr("LoanPmt(monthly_rate, periods, loan_amount)"));
1073.64 using uCalcSoftware; var uc = new uCalc(); // Define a function for the standard loan payment formula uc.DefineFunction("LoanPmt(rate, nper, pv) = Int((rate * pv) / (1 - (1 + rate)^-nper)*100)/100"); // Define variables for the calculation uc.DefineVariable("monthly_rate = 0.05 / 12"); // 5% annual rate uc.DefineVariable("periods = 30 * 12"); // 30 years uc.DefineVariable("loan_amount = 200000"); // $200,000 Console.WriteLine(uc.EvalStr("LoanPmt(monthly_rate, periods, loan_amount)"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
// Define a function for the standard loan payment formula
uc.DefineFunction("LoanPmt(rate, nper, pv) = Int((rate * pv) / (1 - (1 + rate)^-nper)*100)/100");
// Define variables for the calculation
uc.DefineVariable("monthly_rate = 0.05 / 12"); // 5% annual rate
uc.DefineVariable("periods = 30 * 12"); // 30 years
uc.DefineVariable("loan_amount = 200000"); // $200,000
cout << uc.EvalStr("LoanPmt(monthly_rate, periods, loan_amount)") << endl;
}
1073.64 #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; // Define a function for the standard loan payment formula uc.DefineFunction("LoanPmt(rate, nper, pv) = Int((rate * pv) / (1 - (1 + rate)^-nper)*100)/100"); // Define variables for the calculation uc.DefineVariable("monthly_rate = 0.05 / 12"); // 5% annual rate uc.DefineVariable("periods = 30 * 12"); // 30 years uc.DefineVariable("loan_amount = 200000"); // $200,000 cout << uc.EvalStr("LoanPmt(monthly_rate, periods, loan_amount)") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
'// Define a function for the standard loan payment formula
uc.DefineFunction("LoanPmt(rate, nper, pv) = Int((rate * pv) / (1 - (1 + rate)^-nper)*100)/100")
'// Define variables for the calculation
uc.DefineVariable("monthly_rate = 0.05 / 12") '// 5% annual rate
uc.DefineVariable("periods = 30 * 12") '// 30 years
uc.DefineVariable("loan_amount = 200000") '// $200,000
Console.WriteLine(uc.EvalStr("LoanPmt(monthly_rate, periods, loan_amount)"))
End Sub
End Module
1073.64 Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() '// Define a function for the standard loan payment formula uc.DefineFunction("LoanPmt(rate, nper, pv) = Int((rate * pv) / (1 - (1 + rate)^-nper)*100)/100") '// Define variables for the calculation uc.DefineVariable("monthly_rate = 0.05 / 12") '// 5% annual rate uc.DefineVariable("periods = 30 * 12") '// 30 years uc.DefineVariable("loan_amount = 200000") '// $200,000 Console.WriteLine(uc.EvalStr("LoanPmt(monthly_rate, periods, loan_amount)")) End Sub End Module