0
我創建了一個計算貸款的程序,但它並沒有按照我的教授提出的要求進行。可以讓我看到正確的改動。源代碼將會很棒並且節省時間,但是你不需要。貸款計算器更改
繼承人的問題:
寫一個程序,讓用戶在號碼中輸入的年貸款額度和貸款期限,並顯示開始從5%至8%的每個利率每月支付的價款,增加1/8。繼承人樣品運行:
Loan amount: 10000 [Enter]
Numbers of Years: 5: [Enter]
Interest rate Monthly Payment Total Payment
5% 188.71 11322.74
5.125% 189.28 11357.13
繼承人我以前的代碼:
# include <iostream>
# include <iomanip>
# include <cmath>
using namespace std;
int main()
{
double loanAmountA;
double annualRate;
double paymentAmount;
double amountInterest;
double ratePeriod;
double balanceAfter;
double amountApplied;
double balance;
double paymentPeriod;
int paymentsPerYear;
int totalPayments;
int loanCount = 1;
int paymentCount = 1;
bool anotherLoan = true;
char response;
while (anotherLoan == true)
{
cout<<"Enter amount of loan A:$ ";
cin>>loanAmountA;
cout<<endl;
cout<<"Enter annual percentage rate (APR): "<<"%";
cin>>annualRate;
cout<<endl;
cout<<"Enter the number of payments per year: ";
cin>>paymentsPerYear;
cout<<endl;
cout<<"Enter the total number of payments: ";
cin>>totalPayments;
cout<<endl;
cout<<"Payment Payment Amount Amount to Balance after";
cout<<endl;
cout<<"Number Amount Interest Principal This Payment";
cout<<endl;
cin.ignore(80,'\n');
while (paymentCount <=totalPayments)
{
annualRate = annualRate/100;
balance = loanAmountA - totalPayments * paymentAmount;
ratePeriod = balance * annualRate;
paymentAmount = loanAmountA * (totalPayments/paymentsPerYear * annualRate)/totalPayments;
balanceAfter = balance - paymentAmount;
balance = loanAmountA - (paymentCount * paymentAmount);
cout<<left<<setprecision(0)<<setw(3)<<paymentCount;
cout<<setw(13)<<left<<fixed<<setprecision(2)<<paymentAmount;
cout<<setw(26)<<left<<fixed<<setprecision(2)<<ratePeriod;
cout<<setw(39)<<left<<fixed<<setprecision(2)<<balance;
cout<<setw(42)<<left<<fixed<<setprecision(2)<<balanceAfter;
if (paymentCount % 12 == 0)
{
cout<<endl;
cout<<"Hit <Enter> to continue: "<<endl;
cin.ignore(80,'\n');
cin.get();
}
paymentCount++;
loanCount++;
cout<<endl;
}
cout<<"Would you like to calculate another loan? y/n and <enter>";
cin>>response;
if (response == 'n')
{
anotherLoan = false;
cout<<endl<<endl;
cout<<"There were"<<loanCount<< "loans processed.";
cout<<endl<<endl;
}
}
return 0;
}
您必須改進格式。當你編輯這個問題時,玩一下可用的東西。 – 2010-07-25 14:56:59
這不符合教授的指導原則?你從來沒有告訴我們你要解決什麼問題。 – 2010-07-25 15:22:15
哦,爲什麼作業的作業比典型的真實世界編程任務/錯誤更有趣? – 2010-07-25 15:48:41