C语言实现房贷计算器

更新时间:2024-11-06 17:31:07 阅读: 评论:0


2023年5月23日发(作者:华东政法大学教学信息管理系统)

C语⾔实现房贷计算器

⽤C语⾔做⼀个房贷计算计算器,可以选择等额本⾦或等额本息两种模式,可以直接输⼊总额或通过输⼊⾯积*价格计算~

代码:

#include

#include

#include

void f(double all_num);

int main()

{

system("color F0");

system("title 房贷计算");

char c;

void chooseA(); void chooseB();

while (1)

{

printf("请选择模式:n"

"A.根据⾯积、单价计算n"

"B.根据贷款总额计算n");

scanf_s("%c", &c, 4);

switch (c)

{

case 'a':

case 'A':chooseA(); break;

case 'b':

case 'B':chooseB(); break;

default:printf("模式选择有误,请输⼊A/B/a/b选择您想要使⽤的模式。nn");

}

}

return 0;

}

void chooseA()

{

double price, area, all_num;

printf("单价(元/平⽅⽶):");

scanf_s("%lf", &price);

printf("⾯积(平⽅⽶):");

scanf_s("%lf", &area);

all_num = price * area;

f(all_num);

}

void chooseB()

{

double all_num;

printf("请输⼊贷款总额:");

scanf_s("%lf", &all_num);

f(all_num);

}

void f(double all_num)

{

void choose1(double all_num, int num); void choose2(double all_num, int num);

char m, k, kong; int g, o;

printf("按揭成数:");

scanf_s("%d", &o);

scanf_s("%c", &kong, 4);

all_num = all_num * o / 10;

printf("有⽆打折优惠:");

scanf_s("%c", &m, 4);

scanf_s("%c", &kong, 4);

switch (m)

{

case 'y':

case 'Y':printf("折数:"); scanf_s("%d", &g); scanf_s("%c", &kong, 4); all_num = all_num * g / 10; break;

case 'Y':printf("折数:"); scanf_s("%d", &g); scanf_s("%c", &kong, 4); all_num = all_num * g / 10; break;

case 'n':

case '':all_num = all_num; break;

default:printf("模式选择有误,请输⼊Y//y/n选择有⽆打折优惠。nn");

}

printf("n请选择还款模式:n"

"A.等额本息n"

"B.等额本⾦n");

scanf_s("%c", &k, 4);

scanf_s("%c", &kong, 4);

switch (k)

{

case 'a':

case 'A':choose1(all_num, o); break;

case 'b':

case 'B':choose2(all_num, o); break;

default:printf("模式选择有误,请输⼊A/B/a/b选择您想要使⽤的模式。nn");

}

}

void choose1(double all_num, int num)

{

double M_repay, Y_rate, sum = 0, w; char kong;

int m, i = 1;//m,;i,

还款⽉数⽉数

printf("贷款年利率:");

scanf_s("%lf", &Y_rate);

printf("总还款⽉数:");

scanf_s("%d", &m); scanf_s("%c", &kong, 4);

w = pow((1 + Y_rate / 12), m);

M_repay = all_num * Y_rate / 12 * w / (w - 1);//=×[×1+^]÷[1+^-1]

每⽉应还贷款本⾦⽉利率⽉利率)还款⽉数⽉利率)还款⽉数

printf("n每⽉应还%lfn", M_repay);

sum = M_repay * m;

printf("总还款⾦额:%lfn", sum);

printf("⾸期付款:%gn", all_num / num * 10 - all_num);

printf("总利息:%lfnn", sum - all_num);

}

void choose2(double all_num, int num)

{

double M_repay, M_rate, sum = 0; char kong;

int m, i = 1;//m,;i,

还款⽉数⽉数

printf("贷款年利率:");

scanf_s("%lf", &M_rate);

printf("总还款⽉数:");

scanf_s("%d", &m); scanf_s("%c", &kong, 4);

M_repay = all_num / m;//=÷

每⽉应还本⾦贷款本⾦还款⽉数

printf("n");

for (i = 1; i <= m; i++)

{

printf("%d个⽉⽉供额:%lfn", i, M_repay + (all_num - ((double)i - 1) * M_repay) * M_rate / 12); // = (÷)+( -

每⽉⽉供额贷款本⾦还款⽉数贷款本⾦已归

还本⾦累计额⽉利率

sum = sum + M_repay + (all_num - ((double)i - 1) * M_repay) * M_rate / 12;

}

printf("n");

printf("总还款⾦额:%lfn", sum);

printf("⾸期付款:%gn", all_num / num * 10 - all_num);

printf("总利息:%lfnn", sum - all_num);

}

祝各位早⽇买房!


本文发布于:2023-05-23 18:25:36,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/falv/fa/82/101522.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 站长QQ:55-9-10-26