我解决了你们指出的问题(谢谢btw!),但现在它给了我一个无限循环。 我不明白为什么。我mortgageleft是越来越每隔while循环运行时间monthlypayment下降...If Else not running
#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;
}
值检查括号 –
您应该包括您所使用的语言标签花括号。 – brenners1302
您并未更改“MortgageLeft”值。那个'while'循环何时会退出? – DarkKnight