Project 4-38 Compute the interest and print the balance
//============================================================================
// 제출일 : 2005. 3. 12
// 작업환경 : Windows XP SP1, VC++ 6.0, Pentium4
// 연습문제 4-38
//============================================================================
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <string.h>
#include <stdlib.h>
float calc(float input); //이자의 계산
void print(float input); //출력
int main()
{
float begining_balance;
cout << "원금을 입력하세요\n";
cin >> begining_balance;
print(begining_balance); //출력 함수 호출
return 0;
}
float calc(float input) //이자 계산 함수
{
return (float)(input * 0.053);
}
void print (float input) //출력함수 : 이자 계산 함수 호출
{
int loop ;
cout << "============================|\n";
cout << "|Quater| Interest | Total |\n";
cout << "============================|\n";
for (loop = 0; loop < 5 ; loop++)
{
cout.setf( ios::right, ios::adjustfield ); //오른쪽 정렬
cout <<'|'<<setw(6)<<loop <<'|';
cout <<setw(10)<<calc(input)<<'|'; //이자의 계산
input+=calc(input); //계산된 이자를 원금에 합산
cout <<setw(9)<<input<<"|\n"; //최종 잔액 출력
}
cout << "=================================\n";
}