C++ 대출 문제 질문드립니다.

zero5140의 이미지

중간에 cin으로 입력을 받았는데

Loan::Loan()
{
	annualInterestRate = 9.5;
	numberOfYears = 30;
	loanAmount = 100000;
}

이렇게 또 초기화 해주는 이유가
제가 아무 값을 입력 안했을 때 저 값으로 출력 되기 위해서 인가요?

#ifndef LOAN_H	
#define LOAN_H	
 
class Loan		
{
public:		
	Loan();		
	Loan(double rate, int years,double amount);		
	double getAnnualInterestRate();		
	int getNumberOfYears();		
	double getLoanAmount();		
 
	void setAnnualInterestRate(double rate);		
	void setNumberOfYears(int years);		
	void setLoanAmount(double amount);		
 
	double getMonthlyPayment();		
	double getTotalPayment();	
 
private:		
	double annualInterestRate; // 연이율
	int numberOfYears;		//대출 연수
	double loanAmount;		//대출액
 
};
 
#endif 

---------------------------------------------------------
#include <iostream>
#include <iomanip>
#include "Loan.h"
using namespace std;
 
int main()
{
	//연이율 입력
	cout << "연이율 을 입력하세요 예)8.25:";
	double annualInterestRate;
	cin >> annualInterestRate;
 
	//연도 입력
	cout << "연도를 입력하세요 예)8:";
	int numberOfYears;
	cin >> numberOfYears;
 
	//대출액 입력
	cout << "대출액 입력하세요 예)12000.95:";
	double loanAmount;
	cin >> loanAmount;
 
	//Loan 객체 생성
	Loan loan(annualInterestRate, numberOfYears, loanAmount);
 
	//결과 출력
	cout << fixed << setprecision(3);		//소수점 2번째 자리 까지만 출력
	cout << "월 상환액은" << loan.getMonthlyPayment() << endl;
	cout << "총 상환액은" << loan.getTotalPayment() << endl;
 
	return 0;
}

------------------------------------------------------------
#include "Loan.h"
#include <cmath>
using namespace std;
 
Loan::Loan()
{
	annualInterestRate = 9.5;
	numberOfYears = 30;
	loanAmount = 100000;
}
 
Loan::Loan(double rate, int years, double amount)
{
	double annualInterestRate = rate;
	int numberOfYears = years;
	double loanAmount = amount;
}
 
double Loan::getAnnualInterestRate()
{
	return annualInterestRate;
}
 
int Loan::getNumberOfYears()
{
	return numberOfYears;
}
 
double Loan::getLoanAmount()
{
	return loanAmount;
}
 
void Loan::setAnnualInterestRate(double rate)
{
	annualInterestRate = rate;
}
 
void Loan::setNumberOfYears(int years)
{
	numberOfYears = years;
}
 
void Loan::setLoanAmount(double amount)
{
	loanAmount = amount;
}
 
double Loan::getMonthlyPayment()
{
	double monthlyInterestRate = annualInterestRate / 1200;
	return loanAmount * monthlyInterestRate / (1 - (pow(1 / (1 + monthlyInterestRate), numberOfYears * 12)));
}
 
double Loan::getTotalPayment()
{
	return getMonthlyPayment()*numberOfYears * 12;
}
김정균의 이미지

질문을 요약에다 넣으시면 보이지 않습니다. 글 수정을 메뉴를 이용해서, 요약에 있는 질문 내용을 본문으로 옮겨 주세요.

그리고 코드는 <code lang="cpp">~</code> block 으로 감싸 주세요.

zero5140의 이미지

뭐가 잘못된지 모르고 그냥 올렸네요 알려주셔서 감사합니다