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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
| #include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int balance,
date_in,
month_in,
year_in,
date_out,
month_out,
year_out,
duration;
float interest_rate,
final_balance;
char input;
balance = 0;
interest_rate = 0;
final_balance = 0;
int days_per_month[] = {0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Not a leap year
int days_per_month_leap[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Leap year
while (1)
{
printf("Input customer balance : "); scanf("%d", &balance);
if(balance <= 100)
{
interest_rate = 5;
printf("your balance is <= $100, your interest rate is : %.f%%/30 days\n", interest_rate);
}
else if(balance > 100 && balance <= 1000)
{
interest_rate = 7.5;
printf("your balance is <= $1.000, your interest rate is : %.1f%%/30 days\n", interest_rate);
}
else if(balance > 1000)
{
interest_rate = 10;
printf("your balance is > $1.000, your interest rate is : %.f%%/30 days\n", interest_rate);
}
printf("Date\n");
printf(" In : "); scanf("%d-%d-%d", &date_in, &month_in, &year_in);
printf(" Out : "); scanf("%d-%d-%d", &date_out, &month_out, &year_out);
duration = 0;
if(year_in == year_out)
{
int i;
if(month_in == month_out) duration += (date_out - date_in);
else if(year_in % 4 == 0 && year_in % 100 != 0 || year_in % 400 == 0)
{
duration += days_per_month_leap[month_in] - date_in;
}
else duration += days_per_month[month_in] - date_in;
for(i = month_in + 1; i < month_out; i++)
{
if(year_in % 4 == 0 && year_in % 100 != 0 || year_in % 400 == 0) duration += days_per_month_leap[i];
else duration += days_per_month[i];
}
duration += date_out;
}
else
{
int i, century_in, falseleap = 0;
century_in = ((year_in / 100) + 1) * 100;
if(year_in % 4 == 0 && year_in % 100 != 0 || year_in % 400 == 0)
duration = days_per_month_leap[month_in] - date_in;
else
duration = days_per_month[month_in] - date_in;
for(i = month_in + 1; i <= 12; i++)
{
if(year_in % 4 == 0 && year_in % 100 != 0 || year_in % 400 == 0)
duration += days_per_month_leap[i];
else
duration += days_per_month[i];
}
for(i = 1; i < month_out; i++)
{
if(year_out % 4 == 0 && year_out % 100 != 0 || year_out % 400 == 0)
duration += days_per_month_leap[i];
else
duration += days_per_month[i];
}
int leapcount_in = year_in / 4;
int leapcount_out = year_out / 4;
if(year_out % 4 == 0) leapcount_out -= 1;
int leaptotal = leapcount_out - leapcount_in;
for(i = century_in; i < year_out; i += 100)
{
if((i % 400) != 0)
falseleap += 1;
}
duration += 365 * (year_out - year_in - 1) + date_out + leaptotal - falseleap;
}
if(duration <= 0) return(-1); //Input error
printf("You had saved your money for %d days\n", duration);
final_balance = balance;
while(1)
{
if(duration >= 30)
{
duration -= 30;
final_balance += (interest_rate * (final_balance/100));
if(final_balance > 100 && final_balance <= 1000) interest_rate = 7.5;
else if(final_balance > 1000) interest_rate = 10;
}
else if(duration < 30 && duration > 0)
{
duration = 0;
final_balance += ((duration/30) * interest_rate * (final_balance/100));
}
else if(duration == 0) break;
}
printf("\nYour final balance is : %.6f", final_balance);
fflush(stdin);
printf("\nDo you want to restart the program? (y/n) "); scanf("%c", &input);
system("cls");
if(input == 'n') return 0;
}
}
|
0 komentar:
Post a Comment