structs
This commit is contained in:
41
investmentCalculator/app.go
Normal file
41
investmentCalculator/app.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import "math"
|
||||
|
||||
const inflationRate = 2.5
|
||||
var investmentAmount float64
|
||||
var years float64
|
||||
var expectedReturnRate float64
|
||||
|
||||
func main() {
|
||||
|
||||
|
||||
fmt.Print("Investment Amount: ")
|
||||
fmt.Scan(&investmentAmount)
|
||||
|
||||
fmt.Print("Expected Return Rate: ")
|
||||
fmt.Scan(&expectedReturnRate)
|
||||
|
||||
fmt.Print("Years: ")
|
||||
fmt.Scan(&years)
|
||||
|
||||
futureValue := investmentAmount * math.Pow(1 + expectedReturnRate/100, years)
|
||||
futureRealValue := futureValue / math.Pow(1 + inflationRate/100, years)
|
||||
|
||||
formattedFV := fmt.Sprintf("Future Value: %.1f\n", futureValue)
|
||||
formattedRFV := fmt.Sprintf("Future Value (adjusted for inflation): %.1f\n", futureRealValue)
|
||||
|
||||
|
||||
// fmt.Println("Future Value:", futureValue)
|
||||
// fmt.Println("Future Value (adjusted for inflaction):", futureRealValue)
|
||||
|
||||
fmt.Print(formattedFV, formattedRFV)
|
||||
}
|
||||
|
||||
func calculateFutureValues (investmentAmount, expectedFutureValue, years float64) (fv float64, rfv float64) {
|
||||
fv = investmentAmount * math.Pow(1 + expectedReturnRate/100, years)
|
||||
rfv = fv / math.Pow(1 + inflationRate/100, years)
|
||||
|
||||
return fv, rfv
|
||||
}
|
||||
3
investmentCalculator/go.mod
Normal file
3
investmentCalculator/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module example.com/investment-calculator
|
||||
|
||||
go 1.23.1
|
||||
Reference in New Issue
Block a user