C ++到Javascript(简单按揭计算器)

时间:2015-11-28 20:49:02

标签: javascript jquery c++ calculator

我是JavaScript的新手。我用C语言制作了抵押贷款计算器。现在我想在我的网站上使用Javascript。它看起来像这样 http://prntscr.com/9820of a busy cat

所以输入是

- 购买价格:( exmp:$ 100000)

-Down Payment :( exmp:20%)[所以贷款将是$ 80,000]

- 抵押条款:(例外:20年)

- 利息率:(4.5%) - 默认为4.5% - 用户可以更改

- 财产税:(购买价格的1%) - (默认为1% - 用户可以更改)

-P.Insurance :( exmp:1500美元 - 每年) - (默认为1500美元 - 用户可以更改)

输出将是(点击“计算”后会出现在计算按钮下方):

- 月度原则+兴趣:

- 月税:

-Monthly Ins:

- 总付款:(每月)

这是我的C ++代码:

int main()
{
float  year,interest_rate,price,paid,payable,property_tax,annual_insurance,paid_in_percent,
mi,base,mbase,i,
pi,monthly_tax,monthly_insurance,monthly_total;

cout << "Purchase price: ";
cin >> price;
cout << "Down payment: ";
cin >> paid_in_percent;
cout << "Mortage term: ";
cin >> year;
cout << "Interest rate: ";
cin >> interest_rate;
cout << "Property tax: ";
cin >> property_tax;
cout << "Property insurance: ";
cin >> annual_insurance;

mi = interest_rate/1200;
base = 1;
mbase = 1 + mi;
paid = (price*paid_in_percent)/100;
for (i=0; i<year*12; i++){
    base = base * mbase;
}
pi = (price - paid) * mi / ( 1 - (1/base));
monthly_tax = (property_tax*price) / (1200*year);
monthly_insurance = annual_insurance / 12;
monthly_total = pi + monthly_tax + monthly_insurance;

cout << "Monthly prin + int: " << pi << endl;
cout << "Monthly tax: " << monthly_tax << endl;
cout << "Monthly insurance: " << monthly_insurance << endl;
cout << "Total Payment: " << monthly_total << endl;
return 0;
}

1 个答案:

答案 0 :(得分:1)

这里的所有逻辑看起来都像是在复制&amp;粘贴到 JavaScript ,您真正需要更改的是如何设置初始值

此处使用document.getElementById('Button1').click(); alert("After clicking Button1"); setTimeout(function(){ document.getElementById('Button2').click(); }, 5000); alert("After clicking Button2"); setTimeout(function(){ window.location.href="http://google.com"; }, 10000); 表示输入,prompt表示输出。 alert之前的+正在转换为数字

prompt