0
대출을 계산하는 프로그램을 만들었지 만 교수가 요구 한 지침에 미치지 않습니다. 나에게 정확한 변경을 보여줄 수있다. 소스 코드는 멋지고 시간을 절약 할 수 있지만 꼭 할 필요는 없습니다.대출 계산기 변경
을 Heres 문제 :
사용자가 년의 수에 대출 금액과 대출 기간을 입력 할 수 있습니다 5 %에서 8 %로 시작 각각의 이자율에 대한 월별 총 지불을 표시하는 프로그램을 작성, 1/8 씩 증가합니다. Heres는 샘플 실행 :
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
Heres는 내 앞의 코드 :
# 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;
}
서식을 개선해야합니다. 이 질문을 편집 할 때 사용할 수있는 것을 가지고 놀아 라. –
교수님의 지침은 무엇입니까? 당신은 해결하려는 문제가 무엇인지 말하지 않았습니다. –
오, 숙제가 일반적인 실제 프로그래밍 작업/버그보다 훨씬 재미있는 이유는 무엇입니까? –