C언어/C언어 자료실

신용카드 할부 계산 처리 알고리즘

Chipmunks 2016. 7. 22.
728x90


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <stdio.h>
#include <stdlib.h>
 
/*
    2,000,000원을 15.4% 할부수수료율로 6개월 할부
    납부월수    할부잔액    할부원금    할부수수료    월납부액
    1        2,000,000    333,333        25,667        359,000
    2        1,666,667    333,333        21,389        354,722
    3        1,333,334    333,333        17,111        350,344
    4        1,000,001    333,333        12,833        346,166
    5        666,668        333,333        8,556        341,889
    6        333,335        333,333        4,278        337,611
    할부 원금 = 할부잔액 / 개월수
    할부 수수료 = 할부잔액 * 할부수수료율 * 1/12
    월납부액 = 할부원금 + 할부수수료
*/
 
#define MONTHS_OF_YEAR 12
 
/* 초기 지불 정보 */
typedef struct _InitialPayment {
    int principal;                            // 원금
    int installMonth;                        // 할부개월
    double installCommissionRate;            // 할부 수수료율
    int installPrincipal;                    // 할부 원금 ( 반올림 해야 함 )
} InitialPayment;
 
/* 월별 납부 정보 */
typedef struct _InstallmentReport {
    int installMonth;                        // 납부 월수
    int installBalance;                        // 할부 잔액
    int installCommission;                    // 할부 수수료 ( 반올림 해야 함 )
    int paymentMonth;                        // 월 납부액
} InstallmentReport;
 
int main(void) {
    InitialPayment initialpayment = { 0, };
    InstallmentReport* installmentreport;
 
    /* 반복문 변수 */
    int i;
    /* 할부 수수료율 퍼센트 */
    double ratePercent;
 
    /* 초기 지불 정보 설정 */
    printf("\t< 초기 지불 정보를 설정하여 주세요. >\n");
    printf("==========================================================\n");
    
    /* 원금 입력 */
    printf("원금 입력 >> ");
    scanf_s("%d"&initialpayment.principal);
    
    /* 할부 개월 입력 */
    printf("할부 개월 >> ");
    scanf_s("%d"&initialpayment.installMonth);
 
    /* 할부 수수료율 입력 */
    printf("할부 수수료율 ( %% 제외 ) >> ");
    scanf_s("%lf"&ratePercent);
    initialpayment.installCommissionRate = ratePercent / 100;
    /* 할부 원금 계산 */
    /* 정수 반올림 작업 0.5 를 더해 내림 */
    initialpayment.installPrincipal = (double)initialpayment.principal / initialpayment.installMonth + 0.5;
    printf("==========================================================\n");
    /* 월별 납부 정보 계산 */
    /* 할부 개월에 맞게 동적 할당 */
    installmentreport = (InstallmentReport*)malloc(initialpayment.installMonth *
                                                   sizeof(InstallmentReport));
    
    for (i = 0; i < initialpayment.installMonth; i++) {
        /* 납부 월수 계산 */
        installmentreport[i].installMonth = i + 1;
        if (i == 0) {
            /* 처음 할부 잔액 설정 */
            installmentreport[i].installBalance = initialpayment.principal;
        }
        /* 할부 수수료 계산 */
        installmentreport[i].installCommission = installmentreport[i].installBalance *
                                                 initialpayment.installCommissionRate /
                                                 MONTHS_OF_YEAR +
                                                 0.5;
        /* 월 납부액 계산 */
        installmentreport[i].paymentMonth = initialpayment.installPrincipal +
                                            installmentreport[i].installCommission;
        /* 다음 월 할부잔액 계산 */
        if (i == initialpayment.installMonth - 1) {
            /* 마지막 개월은 계산 안함 */
            continue;
        }
        installmentreport[i + 1].installBalance = installmentreport[i].installBalance -
                                                  initialpayment.installPrincipal;
    }
    /* 월별 납부 정보 출력 */
    printf("\t\t< 월별 납부 정보 >\n");
    printf("==========================================================\n");
    printf("납부월수\t할부잔액\t할부원금\t할부수수료\t월납부액\n");
    for (i = 0; i < initialpayment.installMonth; i++) {
        printf("%d\t\t%d\t\t%d\t\t%d\t\t%d\n", i + 1, installmentreport[i].installBalance,
                initialpayment.installPrincipal, installmentreport[i].installCommission,
                installmentreport[i].paymentMonth);
    }
    printf("==========================================================\n");
    return 0;
}
cs




< 실행 화면 >


지식인 답변을 올리려 했지만, 질문글을 삭제해 버리신.. ㅠㅠ

자료실에 놓고 갑니다!


< 첨부 파일 >


신용카드 할부 계산 처리 알고리즘.7z

신용카드 할부 계산 처리.exe



질문과 충고는 환영합니다.

댓글