用于计算淘宝等额本金型贷款,利率当前为万分之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]
Comments(5)
我用codeblocks编译你这个代码,结果error显示”fatal error: iostream: No such file or directory”……
怎么解决啊……
@Cartridge:俺在VS2015中正常,你试下把iostream后面加个“.h”