-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.go
138 lines (112 loc) · 3.21 KB
/
App.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package main
import (
"GoTempConverter/src/temp"
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
userInput()
}
func menu() {
fmt.Println("a) celsius -> fahrenheit")
fmt.Println("b) fahrenheit -> kelvin")
fmt.Println("c) kelvin -> rankine")
fmt.Println("d) rankine -> reaumur")
fmt.Println("e) reaumur -> celsius")
}
func userInput() {
menu()
fmt.Println("choice : ")
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
input := scanner.Text()
switch input {
case "a":
fmt.Println("insert the celsius temperature (int)")
scanner.Scan()
temperatures, _ := strconv.Atoi(scanner.Text())
createC(temperatures)
case "b":
fmt.Println("insert the fahrenheit temperature (int)")
scanner.Scan()
tempF, _ := strconv.Atoi(scanner.Text())
createF(tempF)
case "c":
fmt.Println("insert the kelvin temperature (int)")
scanner.Scan()
tempK, _ := strconv.Atoi(scanner.Text())
createK(tempK)
case "d":
fmt.Println("insert the rankine temperature (int)")
scanner.Scan()
tempRan, _ := strconv.Atoi(scanner.Text())
createRan(tempRan)
case "e":
fmt.Println("insert the reaumur temperature (int)")
scanner.Scan()
tempRea, _ := strconv.Atoi(scanner.Text())
createRea(tempRea)
}
}
func createC(temperature int) {
var c temp.Celsius
if temperature > 23 {
c = temp.Celsius{Temperature: temperature, Category: "hot temperature"}
fmt.Println("celsius temperature : ", c)
} else {
c = temp.Celsius{Temperature: temperature, Category: "cold temperature"}
fmt.Println("celsius temperature : ", c)
}
toFahrenheit := temp.ToFahrenheit(c)
fmt.Println("celsius -> fahrenheit :", toFahrenheit, "Fahrenheit")
}
func createF(tempF int) {
var f temp.Fahrenheit
if tempF > 23 {
f = temp.Fahrenheit{Temperature: tempF, Category: "hot temperature"}
fmt.Println("fahrenheit temperature :", f)
} else {
f = temp.Fahrenheit{Temperature: tempF, Category: "cold temperature"}
fmt.Println("fahrenheit tempereture :", f)
}
toKelvin := temp.ToKelvin(f)
fmt.Println("fahrenheit -> kelvin :", toKelvin, "Kelvin")
}
func createK(tempK int) {
var k temp.Kelvin
if tempK > 22 {
k = temp.Kelvin{Temperature: tempK, Category: "hot temperature"}
fmt.Println("kelvin temperature :", k)
} else {
k = temp.Kelvin{Temperature: tempK, Category: "cold temperature"}
fmt.Println("kelvin temperature :", k)
}
toRankine := temp.ToRankine(k)
fmt.Println("kelvin -> rankine :", toRankine, "Rankine")
}
func createRan(tempRan int) {
var ran temp.Rankine
if tempRan > 20 {
ran = temp.Rankine{Temperature: tempRan, Category: "hot temperature"}
fmt.Println("rankine temperature :", ran)
} else {
ran = temp.Rankine{Temperature: tempRan, Category: "cold temperature"}
fmt.Println("rankine temperature :", ran)
}
toReaumur := temp.ToReaumur(ran)
fmt.Println("rankine -> reaumur :", toReaumur, "reaumur")
}
func createRea(tempRea int) {
var rea temp.Reaumur
if tempRea > 25 {
rea = temp.Reaumur{Temperature: tempRea, Category: "hot temperature"}
fmt.Println("reaumur temperature :", rea)
} else {
rea = temp.Reaumur{Temperature: tempRea, Category: "cold temperature"}
fmt.Println("reaumur temperature :", rea)
}
toCelsius := temp.ToCelsius(rea)
fmt.Println("reaumur -> celsius :", toCelsius, "celsius")
}