-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnual Interest.c
72 lines (58 loc) · 1.3 KB
/
Anual 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
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
float calcAnnualInterest(float interestRate, float amount);
float findTotalAmount(float interestRate, float amount);
void testTotalAmount();
int main(void)
{
float rate,amount,total;
int i;
testTotalAmount();
do
{
printf("Enter Initial Amount to be invested : ");
if(scanf("%f",&amount)!=1)
{
printf("Invalid Input !!");
while(getchar()!='\n');
}
else break ;
}while(true);
do
{
printf("Enter Annual interest Rate(in percentage) : ");
if(scanf("%f",&rate)!=1)
{
printf("Invalid Input !!");
while(getchar()!='\n');
}
else break ;
}while(true);
for(i=1;i<6;i++)
{
total = findTotalAmount(rate,amount);
amount += calcAnnualInterest(rate,amount);
printf("Amount after year 1 : %.2f \n",total);
}
return 0;
}
float calcAnnualInterest(float interestRate, float amount)
{
float AnnualInterest = amount * (interestRate/100);
if (amount>1000000)
AnnualInterest += amount * 0.005;
return AnnualInterest;
}
float findTotalAmount(float interestRate, float amount)
{
float totalAmount,interest;
interest = calcAnnualInterest(interestRate,amount);
totalAmount = interest + amount;
return totalAmount;
}
void testTotalAmount()
{
assert(findTotalAmount(10,1000)==1100);
assert(findTotalAmount(10,2000000)==2210000);
}