-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
218 lines (208 loc) · 6.09 KB
/
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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package main
import (
"fmt"
"math"
"os"
"painter-calc/utils"
)
func main() {
fmt.Println("PAINTING COSTS CALCULATOR\n")
// enter rooms count
var roomsCount int
for {
val, err := utils.GetDataInt("How many rooms do you want to paint? (0-10)")
if err == nil && val >= 0 && val <= 10 {
if val == 0 {
fmt.Println("Bye!")
os.Exit(0)
}
roomsCount = int(val)
fmt.Println("Rooms:", roomsCount)
break
}
fmt.Println("Check your input data")
}
var roomsSurface, wallsFinish []float64
var layers []int
var paintType []string
paints := map[string][]float64{
// name: price, usage
"acrylic": {5.99, 0.15},
"emulsion": {3.19, 0.1},
}
// enter rooms data
for i := 1; i <= roomsCount; i++ {
var wallL, wallH float64
var apertures int
fmt.Printf("\nStart collecting info for Room #%d\n\n", i)
//room length
for {
fmt.Printf("[ROOM %d/%d] ", i, roomsCount)
val, err := utils.GetDataFloat("Enter total length of walls (in meters)")
if err == nil && val > 0 && val <= 100 {
wallL = val
fmt.Println("Length:", wallL)
break
}
fmt.Println("Check your input data")
}
//room height
for {
fmt.Printf("[ROOM %d/%d] ", i, roomsCount)
val, err := utils.GetDataFloat("Enter height of walls (in meters)")
if err == nil && val > 0 && val <= 10 {
wallH = val
fmt.Println("Height:", wallH)
break
}
fmt.Println("Check your input data")
}
//room surface calc
roomsSurface = append(roomsSurface, wallL*wallH)
//get number of doors and windows
for {
fmt.Printf("[ROOM %d/%d] ", i, roomsCount)
val, err := utils.GetDataInt("Enter number of doors/windows (1-100)")
if err == nil && val > 0 && val <= 100 {
apertures = int(val)
fmt.Println("Apertures:", apertures)
break
}
fmt.Println("Check your input data")
}
//doors and windows loop
for j := 1; j <= apertures; j++ {
var apertureH, apertureW float64
//width loop
for {
fmt.Printf("[ROOM %d/%d][Aperture %d/%d] ", i, roomsCount, j, apertures)
val, err := utils.GetDataFloat("Enter aperture width (in meters)")
if err == nil && val > 0 && val <= 10 {
apertureW = val
fmt.Println("Width:", apertureW)
break
}
fmt.Println("Check your input data")
}
for {
fmt.Printf("[ROOM %d/%d][Aperture %d/%d] ", i, roomsCount, j, apertures)
val, err := utils.GetDataFloat("Enter aperture height (in meters)")
if err == nil && val > 0 && val <= 10 {
apertureH = val
fmt.Println("Height:", apertureH)
break
}
fmt.Println("Check your input data")
}
roomsSurface[i-1] -= apertureH * apertureW
}
// fmt.Println(roomsSurface)
// paint loop
for {
fmt.Printf("[ROOM %d/%d] Choose paint type:\n", i, roomsCount)
for name, nums := range paints {
fmt.Printf(" - '%s' paint (%.2fL per sqm, %.2f€ per L\n", name, nums[1], nums[0])
}
val, err := utils.GetDataString("What paint do you want? (type name)")
if err == nil {
_, ok := paints[val]
if ok {
// fmt.Println(chkPaint)
paintType = append(paintType, val)
break
}
}
fmt.Println("Check your input data")
}
//finish loop
for {
fmt.Printf("[ROOM %d/%d] Choose current walls finish:\n", i, roomsCount)
fmt.Println("0 - smooth \n... \n10 - 10mm diameter bumps")
val, err := utils.GetDataInt("Enter walls finish (0-10)")
if err == nil && val >= 0 && val <= 10 {
wallsFinish = append(wallsFinish, float64(val)/10+1)
fmt.Printf("Bumps: %dmm\n", val)
break
}
fmt.Println("Check your input data")
}
//layers loop
for {
fmt.Printf("[ROOM %d/%d] ", i, roomsCount)
val, err := utils.GetDataInt("How many layers of paint is needed (1-5)")
if err == nil && val >= 1 && val <= 5 {
layers = append(layers, int(val))
fmt.Println("Layers:", val)
break
}
fmt.Println("Check your input data")
}
}
//ask for painters
var workers int
for {
fmt.Println("\nSERVICE: ")
fmt.Println(" 0 - You will do it by your self")
fmt.Println(" 1 - Hire our 'BrushCo Ltd' painters")
fmt.Println(" 2 - Get our highly trained monkeys")
val, err := utils.GetDataInt("Choose who is going to paint your house (0-2)")
if err == nil && val >= 0 && val <= 2 {
workers = int(val)
break
}
fmt.Println("Check your input data")
}
//perform calculations
var totalSurface, totalPaint []float64
fmt.Println("\nHOW MUCH WILL IT COST")
for i := 0; i < roomsCount; i++ {
fmt.Printf("\nROOM #%d\n", i+1)
if roomsSurface[i] <= 0 {
roomsSurface[i] = 0
}
resSurface := roomsSurface[i] * float64(layers[i])
totalSurface = append(totalSurface, resSurface)
fmt.Printf("Walls' surface: %.2f sqm\n", roomsSurface[i])
fmt.Printf("Total surface: %.2f sqm (%d layers of %s paint)\n", totalSurface[i], layers[i], paintType[i])
paintUsage := paints[paintType[i]][1] * wallsFinish[i]
fmt.Printf("Paint usage per sqm: %.2fL\n", paintUsage)
paintForRoom := resSurface * paintUsage
fmt.Printf("Paint needed: %.2fL\n", paintForRoom)
totalPaint = append(totalPaint, paintForRoom*paints[paintType[i]][0])
fmt.Printf("Paint costs: %.2f€\n", totalPaint[i])
}
var surfaceToPaint float64
for _, x := range totalSurface {
surfaceToPaint += x
}
var paintCost float64
for _, x := range totalPaint {
paintCost += x
}
const workersPrice float64 = 4.25
const monkeysPrice float64 = 0.7
bananas := int(math.Floor(surfaceToPaint * monkeysPrice))
switch workers {
case 1:
fmt.Println("\nSERVICE")
fmt.Printf("\n'BrushCo Ltd' painters: %.2f€\n", surfaceToPaint*workersPrice)
case 2:
fmt.Println("\nSERVICE")
fmt.Printf("\nHighly trained monkeys: %d bananas\n", bananas)
}
// fmt.Println(totalSurface)
// fmt.Println(totalPaint)
fmt.Println("\n\n === TOTAL ===")
fmt.Printf("\nPaint: %.2f€\n", paintCost)
switch workers {
case 0:
fmt.Println("\nService: 0€")
fmt.Printf("\nTotal: %.2f€\n", paintCost)
case 1:
fmt.Printf("\nService: %.2f€\n\n", surfaceToPaint*workersPrice)
fmt.Printf("\nTotal: %.2f€\n", paintCost+surfaceToPaint*workersPrice)
case 2:
fmt.Printf("\nService: %d bananas\n\n", bananas)
fmt.Printf("\nTotal: %.2f€ + %d bananas\n", paintCost, bananas)
}
}