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의 이미지

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

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.