-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathcomplete.go
60 lines (53 loc) · 1.22 KB
/
complete.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
58
59
60
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.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.",
)
}