等额本息还款器求解中间的计算过程没错为什么运行结果不对嘞
中间计算过程求大佬解释 发下代码 大马强 发表于 2022-1-6 16:05发下代码
#include<stdio.h>
#include<math.h>
int main()
{
float price, area, yir, mir; //单价、面积、年利率、月利率
float interest, loan;//利息,贷款总额
float ave_repay, down_payment;// 月均还款、首付
float total_price, total_repay;//房款总额,还款总额
int ratio, time; //按揭成数,按揭年数
printf("请输入单价(元/平方):");
scanf("%f",&price);
printf("请输入面积:");
scanf("%f",&area);
printf("请输入按揭成数:");
scanf("%f",&ratio);
printf("请输入按揭年数:");
scanf("%f",&time);
printf("请输入当前基准年利率:");
scanf("%f",&yir);
mir = yir / 12 / 100;
ratio = (float)ratio / 10;
total_price = price * area;
down_payment = total_price * (1 - (float)ratio);
loan = total_price * ratio / 10;
total_repay = loan + interest;
interest = time * 12 * ave_repay - loan;
ave_repay = loan *mir * pow((1 + mir), time*12) / pow((1+mir),12*time) - 1;
printf("=================报告结果=================\n");
printf("房款总额:%.2f元\n",total_price);
printf("首期付款:%.2f元\n",down_payment);
printf("贷款总额:%.2f元\n",loan);
printf("还款总额:%.2f元\n",total_repay);
printf("支付利息:%.2f元\n",interest);
printf("月均还款:%.2f元\n",ave_repay);
return 0;
} 两个问题
一、ratio是个整型,装不了浮点数,所以声明要改
二、ave_repay放的位置不对,前边引用了都找不到值
#include<stdio.h>
#include<math.h>
int main()
{
float price, area, yir, mir; //单价、面积、年利率、月利率
float interest, loan;//利息,贷款总额
float ave_repay, down_payment;// 月均还款、首付
float total_price, total_repay, ratio;;//房款总额,还款总额 按揭成数,
// int ratio, time; //按揭成数,按揭年数
int time; //按揭年数
// printf("请输入单价(元/平方):");
// scanf("%f",&price);
// printf("请输入面积:");
// scanf("%f",&area);
// printf("请输入按揭成数:");
// scanf("%d",&ratio);//%d
// printf("请输入按揭年数:");
// scanf("%f",&time);
// printf("请输入当前基准年利率:");
// scanf("%f",&yir);
price = 6000;
area = 120;
ratio = 7;
time = 20;
yir = 5.4;
mir = yir / 12 / 100;
// ratio = (float)ratio / 10;
ratio = ratio / 10;
printf("%f,%f\n",mir,ratio);
total_price = price * area;
down_payment = total_price * (1.0 - ratio);
loan = total_price * ratio / 10;
total_repay = loan + interest;
ave_repay = loan *mir * pow((1 + mir), time*12) / pow((1+mir),12*time) - 1;
printf("%d,%f,%f\n",time, ave_repay, loan);
interest = time * 12 * ave_repay - loan;
// ave_repay = loan *mir * pow((1 + mir), time*12) / pow((1+mir),12*time) - 1; 上边都引用了,你顺序不对
printf("=================报告结果=================\n");
printf("房款总额:%.2f元\n",total_price);
printf("首期付款:%.2f元\n",down_payment);
printf("贷款总额:%.2f元\n",loan);
printf("还款总额:%.2f元\n",total_repay);
printf("支付利息:%.2f元\n",interest);
printf("月均还款:%.2f元\n",ave_repay);
return 0;
}
大马强 发表于 2022-1-6 18:51
两个问题
一、ratio是个整型,装不了浮点数,所以声明要改
二、ave_repay放的位置不对,前边引用了都找不 ...
我看错了,顺序不对的不止一处,我又改了,你自己比对看看,要注意引用变量前要确保里面有东西,不然会出错
=================报告结果=================
房款总额:720000.00元
首期付款:216000.02元
贷款总额:50400.00元
还款总额:54192.00元
支付利息:3792.00元
月均还款:225.80元
#include<stdio.h>
#include<math.h>
int main()
{
float price, area, yir, mir; //单价、面积、年利率、月利率
float interest, loan;//利息,贷款总额
float ave_repay, down_payment;// 月均还款、首付
float total_price, total_repay, ratio;;//房款总额,还款总额 按揭成数,
// int ratio, time; //按揭成数,按揭年数
int time; //按揭年数
// printf("请输入单价(元/平方):");
// scanf("%f",&price);
// printf("请输入面积:");
// scanf("%f",&area);
// printf("请输入按揭成数:");
// scanf("%d",&ratio);//%d
// printf("请输入按揭年数:");
// scanf("%f",&time);
// printf("请输入当前基准年利率:");
// scanf("%f",&yir);
price = 6000;
area = 120;
ratio = 7;
time = 20;
yir = 5.4;
mir = yir / 12 / 100;
// ratio = (float)ratio / 10;
ratio = ratio / 10;
total_price = price * area;
down_payment = total_price * (1.0 - ratio);
loan = total_price * ratio / 10;
ave_repay = loan *mir * pow((1 + mir), time*12) / pow((1+mir),12*time) - 1;
interest = time * 12 * ave_repay - loan;
total_repay = loan + interest;
// printf("%d,%f,%f\n",time, ave_repay, loan);
// ave_repay = loan *mir * pow((1 + mir), time*12) / pow((1+mir),12*time) - 1; 上边都引用了,你顺序不对
printf("=================报告结果=================\n");
printf("房款总额:%.2f元\n",total_price);
printf("首期付款:%.2f元\n",down_payment);
printf("贷款总额:%.2f元\n",loan);
printf("还款总额:%.2f元\n",total_repay);
printf("支付利息:%.2f元\n",interest);
printf("月均还款:%.2f元\n",ave_repay);
return 0;
} 大马强 发表于 2022-1-6 18:53
我看错了,顺序不对的不止一处,我又改了,你自己比对看看,要注意引用变量前要确保里面有东西,不然会出 ...
调试过后给回复呀,谢谢大佬 来学习代码
页:
[1]