淘宝等金本息贷款计算器

用于计算淘宝等额本金型贷款,利率当前为万分之2.1,实际结果比淘宝的还精确(淘宝只保留到小数点后2位)。

自动从系统时间判断闰年,因此如果系统时间错误可能会导致1天的误差。

下载地址

[cpp]#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include<time.h>
using namespace std;

void main(void)
{
double P{}, R{}, sum{};
int N{}, start{}, M[]{ 31,28,31,30,31,30,31,31,30,31,30,31 };
struct tm local;
time_t t{ time(NULL) };
localtime_s(&local,&t);
int years{ local.tm_year + 1901 };

M[1] += ((0 == years% 400) || (0 != years%100) && (0 == years%4)) ? 1 : 0;
//cout << years << endl << M[1]<<endl;

cout << “输入当前执行利率,如万分之5则键入5:”;
cin >> R;
R /= 10000;
cout << “输入本金,如一万块则键入10000:”;
cin >> P;
cout << “输入期数,如一年则键入12:”;
cin >> N;
cout << “输入起始月份,如当前为9月则键入9:”;
cin >> start;

for (int i{ 1 }; N > 0; P -= P / N, N–, i++, start++)
{
double mon{ P*R*M[(start – 1) % 12]+P/N };
cout << “第” << i << “次需还本息:” << mon << endl;
sum += mon;
}
cout << “共计:” << sum << endl;
system(“Pause”);
}[/cpp]

《淘宝等金本息贷款计算器》由“Youling”原创,非授权禁止转载!
(1)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
Youling的头像Youling
上一篇 2015年9月7日 下午3:49
下一篇 2016年1月9日 上午10:15

相关推荐

回复 Cartridge

您的电子邮箱地址不会被公开。 必填项已用*标注

评论列表(5条)

  • Cartridge的头像
    Cartridge 2016年2月8日 上午11:17

    我用codeblocks编译你这个代码,结果error显示”fatal error: iostream: No such file or directory”……

    怎么解决啊……

    • youling的头像
      Youling 2016年2月8日 下午3:03

      @Cartridge俺在VS2015中正常,你试下把iostream后面加个“.h”