Lv 4

# C語言, 邏輯問題

"債 加上 利息" 付清

#include <stdio.h>

#define monthInAYear 12int main ()

{

//初化

double sellingPrice; 想買東西的價錢

double downPayment; 頭款

double annualInterestRate; 年利率

double monthlyPayment; 月度付款

double loanBalance; 債 (想買的東西 減掉 頭款)

double monthlyInterestRate; 月利率 (年利率 除以 定數12 )

double interest; 利息(債 成以 月利率)

double paymentTowardLoan; 拿去付債的錢 (月度付款 減掉 利息)

int counter; 算loop幾次的東西

//跟user拿資料

printf("Enter the amount of Selling Price (Amount of Loan)\n");

scanf("%lf", &sellingPrice);

printf("Enter the amount of Down Payment\n");

scanf("%lf", &downPayment);

printf("Enter the Annual Interest Rate in decimal value \n");

scanf("%lf", &annualInterestRate);

printf("Enter the Payment size (Your Monthly Payment)\n");

scanf("%lf", &monthlyPayment);//不太懂這些是不要放在Loop裡面?

loanBalance = sellingPrice - downPayment;

monthlyInterestRate = annualInterestRate / monthInAYear;

interest = loanBalance * monthlyInterestRate;

paymentTowardLoan = monthlyPayment - interest;

//Loop 直到 債 = 0.00

counter = 0;

while( loanBalance > 0 ) 當債 "大於" 0

{

if ( monthlyPayment < interest ) 當月度付款 "小於" 利息

{這是我寫來停止Loop的

printf("Your loan will not be paid off! Please enter a larger amount of Monthly Payment");

}

else試著把債付掉

{

counter++; 債 = 債 減掉 拿去負債的錢

loanBalance = loanBalance - paymentTowardLoan;

}

}

if( loanBalance < monthlyPayment ) 當剩下的債 小於 月度付款

{ 月度付款 = 債 + 利息

monthlyPayment = loanBalance + interest;

}

return 0;

}

### 2 個解答

• 1 0 年前
最佳解答

#include <stdio.h>

#define monthInAYear 12

int main ()

{

//初化

double sellingPrice; //想買東西的價錢

double downPayment; //頭款

double annualInterestRate; //年利率

double monthlyPayment; //月度付款

double loanBalance; //債 (想買的東西 減掉 頭款)

double monthlyInterestRate; //月利率 (年利率 除以 定數12 )

double interest; //利息(債 成以 月利率)

double paymentTowardLoan; //拿去付債的錢 (月度付款 減掉 利息)

int counter; //算loop幾次的東西

//跟user拿資料

printf("Enter the amount of Selling Price (Amount of Loan): ");

scanf("%lf", &sellingPrice);

printf("Enter the amount of Down Payment: ");

scanf("%lf", &downPayment);

loanBalance = sellingPrice - downPayment;

if (loanBalance > 0) //頭期款＜貸款 才需分期流程

{

printf("Enter the Annual Interest Rate in decimal value(%%): ");

scanf("%lf", &annualInterestRate);

printf("Enter the Payment size (Your Monthly Payment): ");

scanf("%lf", &monthlyPayment);

monthlyInterestRate = annualInterestRate / monthInAYear / 100.;

interest = loanBalance * monthlyInterestRate;

while ( monthlyPayment < interest ) //當 月付款 ＜ 首期利息

{

printf("Your loan will not be paid off! Please enter a larger amount of Monthly Payment\n");

printf("Enter the Payment size (Your Monthly Payment): ");

scanf("%lf", &monthlyPayment);

}

}

counter = 0;

printf("%4s%10s%10s%10s%10s\n", "期別", "債額", "月付額", "利息", "償債");

while( loanBalance > 0 )

{

interest = (double)(int)(loanBalance * monthlyInterestRate+ .5);

paymentTowardLoan = monthlyPayment - interest;

counter++;

if (loanBalance < paymentTowardLoan)

{

monthlyPayment = loanBalance + interest;

paymentTowardLoan = loanBalance;

}

printf("%4d%10.0f%10.0f%10.0f%10.0f\n",

counter,loanBalance,monthlyPayment,interest,paymentTowardLoan);

loanBalance -= paymentTowardLoan; //債 = 債 減掉 拿去負債的錢

}

system("pause");

return 0;

}

• 匿名使用者
7 年前

專辦：

房屋貸款、民間二胎代償、代墊、土地貸款、民間二胎借款、

汽車貸款、中古車貸款、房屋轉增貸、轉貸降息、信用貸款

歡迎你的加入:LineID: hot777

銀行貸款資訊 - 免費諮詢評估 - ( 0986 )-( 377 )-( 776 )

YES貸款理財，提供您提供你最新理債及房屋貸款資訊建議，讓你生活免煩惱。

- -歡迎同業配合- -- -歡迎同業配合- -

歡迎同業配合，若有打擾之處，敬請見諒！