我解決了你們指出的問題(謝謝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