CurrentLoan
将与LoanAmount
相同,然后按月付款金额更改。
它只打印出CurrentLoan
代码的1行并停止,有人知道为什么吗?
void main()
{
float LoanAmount;
float APR;
float Monthly; /*Prompts Number to a Float characrter type*/
float DailyInt;
float OutstandingLoan;
float CurrentLoan;
int i, Day, Month, Year;
i = 0;
Day = 0; /* Day = 1 Day */
Month = Day * 30; /* 30 days per month = Month * 30 days*/
Year == Month * 12; /* 12 months per yar * 30 days per month */
printf(" Please enter in the Loan Amount : \n\r"); /*prompts user to enter float*/
scanf("%f", &LoanAmount);
printf("Please enter in the interest rate as a precentage per year (APR) : \n\r");
scanf("%f", &APR);
printf("Please enter in the Monthly payment plan : \n\r");
scanf("%f", &Monthly);
printf("\nPerforming calculation using a loan of Loan Amount: %.2f \n\r", LoanAmount);
printf("with a monthly payment of : %.0f \n\r", Monthly);
printf("and an APR rate of : %.2f \n\r", APR);
printf("\n Month \ | Year \ | Current Loan \ | Daily Interest \| total Interest\n\r");
for (CurrentLoan = LoanAmount; CurrentLoan == 0; ++CurrentLoan);
{
CurrentLoan += Monthly;
printf("%.2f \n\r", CurrentLoan);
};
return(0);
}
答案 0 :(得分:1)
要回答您的具体问题,为什么它只打印一次,这是因为您的print语句不在循环中。
for (CurrentLoan = LoanAmount; CurrentLoan == 0; ++CurrentLoan); // <-- this semicolon is the problem
分号将你的作用域括号与循环分开,所以基本上你是循环并且什么也不做,然后当你完成循环时,你会进行算术和打印。
答案 1 :(得分:0)
一些问题 - 超出一年==天......:
一个工作示例(循环 - 我没有完成APR部分,因为它似乎不是你的问题):
int main(int argc, char** argv) {
float LoanAmount;
float Monthly; /*Prompts Number to a Float character type*/
printf("Please enter in the Loan Amount : \n\r"); /*prompts user to enter float*/
scanf("%f", &LoanAmount);
printf("Please enter in the Monthly payment plan : \n\r");
scanf("%f", &Monthly);
printf("\nPerforming calculation using a loan of Loan Amount: %.2f \n\r", LoanAmount);
printf("with a monthly payment of : %.0f \n\r", Monthly);
for (; LoanAmount >= 0; LoanAmount -= Monthly) {
printf("%.2f \n\r", LoanAmount);
}
return (0);
}
的变化:
输出:
Please enter in the Loan Amount :
11111
Please enter in the Monthly payment plan :
1949
Performing calculation using a loan of Loan Amount: 11111.00
with a monthly payment of : 1949
11111.00
9162.00
7213.00
5264.00
3315.00
1366.00