gpt4 book ai didi

c - 如果其他没有运行

转载 作者:行者123 更新时间:2023-11-30 18:30:07 26 4
gpt4 key购买 nike

我修复了你们指出的问题(谢谢顺便说一句!),但现在它给了我一个无限循环。我不明白为什么。每次 while 循环运行时,我的抵押贷款余额都会随着每月还款额而减少...

#include <stdlib.h>


int main(){
float MortgageLeft, InterestRate, MonthlyPayment, MonIntRate, AmountOwed;
int Month=0;

printf("What is the value left on the mortgage?\n");
scanf("%f", &MortgageLeft);

printf("What is the annual interest rate of the loan, in percent?\n");
scanf("%f", &InterestRate);

printf("What is the monthly payment?\n\n");
scanf("%f", &MonthlyPayment);

MonIntRate= (InterestRate/12)/100;

printf("Month\t\t Payment\t\t Amount Owed");

while (MortgageLeft>0){
MortgageLeft=(MortgageLeft*MonIntRate)+MortgageLeft;
if(MortgageLeft>MonthlyPayment)
{
MortgageLeft=MortgageLeft-MonthlyPayment;
Month++;
printf("%d\t\t %.2f\t\t %.2f", Month, MonthlyPayment, MortgageLeft);
}

}
return 0;
}

最佳答案

您的 while 循环缺少任何括号,因此它仅执行循环中的下一条语句 AmountOwed=(MortgageLeft*MonIntRate)+MortgageLeft;,该语句永远不会更改循环条件。无限循环意味着您永远不会到达 if/else

关于c - 如果其他没有运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32899687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com