From 0d716f8255c3ac41d871a4742ef691da73407cd6 Mon Sep 17 00:00:00 2001 From: noahspannbauer Date: Thu, 17 Oct 2024 00:39:02 +0000 Subject: [PATCH] go go --- app.go | 41 +++++++++++++++++++++++++++++++++++++++++ go.mod | 3 +++ profitCalculator/app.go | 33 +++++++++++++++++++++++++++++++++ profitCalculator/go.mod | 3 +++ 4 files changed, 80 insertions(+) create mode 100644 go.mod create mode 100644 profitCalculator/app.go create mode 100644 profitCalculator/go.mod diff --git a/app.go b/app.go index e69de29..0914a4e 100644 --- a/app.go +++ b/app.go @@ -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 +} \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8b5015c --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module example.com/investment-calculator + +go 1.23.1 diff --git a/profitCalculator/app.go b/profitCalculator/app.go new file mode 100644 index 0000000..73b8cd7 --- /dev/null +++ b/profitCalculator/app.go @@ -0,0 +1,33 @@ +package main + +import "fmt" + +func main() { + var revenue float64 + var expenses float64 + var taxRate float64 + + fmt.Print("Revenue: ") + fmt.Scan(&revenue) + + fmt.Print("Expenses: ") + fmt.Scan(&expenses) + + fmt.Print("Tax Rate: ") + fmt.Scan(&taxRate) + + ebt := revenue - expenses + profit := ebt * (1 - taxRate/100) + ratio := ebt / profit + + fmt.Println(ebt) + fmt.Println(profit) + fmt.Println(ratio) +} + +func getUserInput(infoText string) float64 { + var userInput float64 + fmt.Print(infoText) + fmt.Scan(&userInput) + return userInput +} \ No newline at end of file diff --git a/profitCalculator/go.mod b/profitCalculator/go.mod new file mode 100644 index 0000000..e50f054 --- /dev/null +++ b/profitCalculator/go.mod @@ -0,0 +1,3 @@ +module example.com/profit-calculator + +go 1.23.1