mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-17 18:51:17 +00:00
first
This commit is contained in:
37
course/7-loops/exercises/3-while/code.go
Normal file
37
course/7-loops/exercises/3-while/code.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func getMaxMessagesToSend(costMultiplier float64, maxCostInPennies int) int {
|
||||
actualCostInPennies := 1.0
|
||||
maxMessagesToSend := 0
|
||||
for {
|
||||
maxMessagesToSend++
|
||||
actualCostInPennies *= costMultiplier
|
||||
}
|
||||
return maxMessagesToSend
|
||||
}
|
||||
|
||||
// don't touch below this line
|
||||
|
||||
func test(costMultiplier float64, maxCostInPennies int) {
|
||||
maxMessagesToSend := getMaxMessagesToSend(costMultiplier, maxCostInPennies)
|
||||
fmt.Printf("Multiplier: %v\n",
|
||||
costMultiplier,
|
||||
)
|
||||
fmt.Printf("Max cost: %v\n",
|
||||
maxCostInPennies,
|
||||
)
|
||||
fmt.Printf("Max messages you can send: %v\n",
|
||||
maxMessagesToSend,
|
||||
)
|
||||
fmt.Println("====================================")
|
||||
}
|
||||
|
||||
func main() {
|
||||
test(1.1, 5)
|
||||
test(1.3, 10)
|
||||
test(1.35, 25)
|
||||
}
|
||||
Reference in New Issue
Block a user