forked from uia-worker/minyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (45 loc) · 973 Bytes
/
main.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
package main
import (
"bufio"
"fmt"
"os"
"github.com/SSneakySnek/minyr/yr"
)
func main() {
for {
fmt.Println("Choose convert, average or exit:")
input := readInput()
switch input {
case "convert":
fmt.Println("Converting all units of Celsius to Farenheit.")
yr.ConvertTemperature()
case "average":
fmt.Println("Average temperature calculator")
yr.AverageTemperature()
readInput() // Add this line to clear any extra newline characters from the input buffer
for {
fmt.Println("Quit? (y/n)")
input2 := readInput()
if input2 == "y" {
break
} else if input2 == "n" {
yr.AverageTemperature()
} else {
fmt.Println("Invalid input, try again")
}
}
case "exit":
fmt.Println("Exiting program.")
return
default:
fmt.Println("Invalid input, try again")
}
}
}
func readInput() string {
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
return scanner.Text()
}
return ""
}