mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-18 03:01:16 +00:00
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func sendSMSToCouple(msgToCustomer, msgToSpouse string) (float64, error) {
|
|
cost, err := sendSMS(msgToCustomer)
|
|
if err != nil {
|
|
return 0.0, err
|
|
}
|
|
|
|
costSpouse, err := sendSMS(msgToSpouse)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return costSpouse + cost, nil
|
|
}
|
|
|
|
// don't edit below this line
|
|
|
|
func sendSMS(message string) (float64, error) {
|
|
const maxTextLen = 25
|
|
const costPerChar = .0002
|
|
if len(message) > maxTextLen {
|
|
return 0.0, fmt.Errorf("can't send texts over %v characters", maxTextLen)
|
|
}
|
|
return costPerChar * float64(len(message)), nil
|
|
}
|
|
|
|
func test(msgToCustomer, msgToSpouse string) {
|
|
defer fmt.Println("========")
|
|
fmt.Println("Message for customer:", msgToCustomer)
|
|
fmt.Println("Message for spouse:", msgToSpouse)
|
|
totalCost, err := sendSMSToCouple(msgToCustomer, msgToSpouse)
|
|
if err != nil {
|
|
fmt.Println("Error:", err)
|
|
return
|
|
}
|
|
fmt.Printf("Total cost: $%.4f\n", totalCost)
|
|
}
|
|
|
|
func main() {
|
|
test(
|
|
"Thanks for coming in to our flower shop today!",
|
|
"We hope you enjoyed your gift.",
|
|
)
|
|
test(
|
|
"Thanks for joining us!",
|
|
"Have a good day.",
|
|
)
|
|
test(
|
|
"Thank you.",
|
|
"Enjoy!",
|
|
)
|
|
test(
|
|
"We loved having you in!",
|
|
"We hope the rest of your evening is absolutely fantastic.",
|
|
)
|
|
}
|