-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterest.c
192 lines (186 loc) · 3.26 KB
/
interest.c
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define turbo 0
void clear()
{
fflush(stdin);
}
int grange(char a[20],int range)
{
int b;
#if turbo == 1
textcolor(RED+BLINK);
#endif
b = strlen(a);
if(b<=range)
{
return (a);
}
else
{
cprintf("Sorry Out of range...\a");
printf("\n");
cprintf("Please enter in range");
printf("\n");
gets(a);
grange(a,range);
}
}
int gfloat(int range)
{
char b[20],*c,d[20];
int value = 1,i,j = 0,k,e;
#if turbo == 1
textcolor(RED+BLINK);
#endif
while (value == 1) //Loop for checking numeric or alphabetic input
{
clear();
gets(b);
c = grange(b,range);
for (i = 0;i <= 20;i++)
{
d[i] = *(c+i);
}
i = strlen(d);
for(k = 0;k<i;k++)
{
e = isdigit(d[k]);
clear();
if(d[k] == '.')
{
j = 0;
}
else if(e>0)
{
j = 0;
}
else
{
j = 1;
break;
}
}
if (j == 0)
{
return atof(d);
break;
}
else
{
cprintf("Please enter an appropiate value");
printf("\n");
}
}
}
void si()
{
float p, r, t;
long double smi;
printf("\nEnter the total amount\n");
p = gfloat(6);
printf("Enter the rate of interest\n");
r = gfloat(3);
printf("Enter the total time in year\n");
t = gfloat(3);
smi = (p * r * t) / 100;
#if turbo == 1
textcolor(GREEN);
#endif
cprintf("simple interest: %.2Lf", smi);
printf("\n");
cprintf("Amount with interest: %.2Lf", smi + p);
printf("\n\n");
}
void ci()
{
float p, r, t, n;
long double cmi;
printf("\nEnter the total amount\n");
p = gfloat(6);
printf("Enter the rate of interest\n");
r = gfloat(2);
printf("Enter the total time in year\n");
t = gfloat(2);
printf("How many times interest compounded per year\n");
n = gfloat(1);
cmi = p * pow((1 + r / (100 * n)), n * t);
#if turbo == 1
textcolor(GREEN);
#endif
cprintf("Compounded interest: %.2Lf", cmi - p);
printf("\n");
cprintf("Amount with interest: %.2Lf", cmi);
printf("\n\n");
}
int main()
{
int i;
char type,l;
system("cls");
i = 1;
while (i < 2) //To calculate repeatedly
{
clear();
printf("Which type of interest you want to calculate?\n");
printf("Compound(c) / Simple(s) / Exit(e)\n");
clear();
#if turbo == 1
textcolor(WHITE);
#endif
type = getche();
if (type == 'c')
{
ci();
}
else if (type == 's')
{
si();
}
else if (type == 'e')
{
printf("\nGood bye");
break;
}
else
{
#if turbo == 1
textcolor(RED+BLINK);
#endif
printf("\n");
cprintf("You have entered a wrong keyword");
printf("\n");
cprintf("Please type again");
printf("\n");
continue;
}
#if turbo == 1
textcolor(WHITE);
#endif
printf("Do you want to calcualte again?(y/n) ");
rep:
clear();
l = getche();
if( l == 'y')
{
printf("\n");
}
else if (l == 'n')
{
printf("\nGood bye\n");
break;
}
else
{
#if turbo == 1
textcolor(RED+BLINK);
#endif
printf("\n");
cprintf("Please enter appropiate keyword\a");
printf("\n");
goto rep;
}
}
return 0;
}