-
Notifications
You must be signed in to change notification settings - Fork 0
/
floatexample.go
57 lines (43 loc) · 1.05 KB
/
floatexample.go
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
package main
import (
"fmt"
)
func main() {
fmt.Println(InterestRate(200.75))
fmt.Println(Interest(200.75))
fmt.Println(AnnualBalanceUpdate(200.75))
balance := 200.75
targetBalance := 214.88
fmt.Println(YearsBeforeDesiredBalance(balance, targetBalance))
}
func InterestRate(balance float64) float32 {
var Interest float32 = 0.00
if balance <= 0 {
Interest = 3.213
} else if balance > 0 && balance < 1000 {
Interest = 0.5
} else if balance >= 1000 && balance < 5000 {
Interest = 1.621
} else {
Interest = 2.475
}
return Interest
}
func Interest(balance float64) float64 {
var calculateInterest float64
calculateInterest = balance * (float64)(InterestRate(balance)/100)
return calculateInterest
}
func AnnualBalanceUpdate(balance float64) float64 {
var balanceUpdate float64
balanceUpdate = balance + Interest(balance)
return balanceUpdate
}
func YearsBeforeDesiredBalance(balance, targetBalance float64) int {
noofYears := 0
for balance <= targetBalance {
noofYears++
balance = balance + Interest(balance)
}
return noofYears
}