forked from snychka/golang-temperature-converter-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (34 loc) · 865 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
package main
import (
"errors"
"fmt"
"os"
)
var originUnit string
var originValue float64
var shouldConvertAgain string
var err error
var errInvalidArguments = errors.New("Invalid arguments")
var errReadingInput = errors.New("Error reading input")
func main() {
for {
fmt.Print("What is the current temperature in " + originUnit + " ? ")
fmt.Print("Would you like to convert another temperature ? (y/n) ")
if shouldConvertAgain != "Y" {
fmt.Println("Good bye!")
break
}
}
}
func printError(err error) {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
func convertToCelsius(value float64) {
convertedValue := (value - 32) * 5 / 9
fmt.Printf("%v F = %.0f C\n", value, convertedValue)
}
func convertToFahrenheit(value float64) {
convertedValue := (value * 9 / 5) + 32
fmt.Printf("%v C = %.0f F\n", value, convertedValue)
}