Last active
April 8, 2017 18:11
-
-
Save artivnv/a6f70feccfcd2032c3b58f54400a1a0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
unitNames := []string{"m", "mm", "cm", "dm"} | |
unitK := []float64{1, 0.001, 0.01, 0.1} | |
fmt.Print("Введите длину: ") | |
var length float64 | |
fmt.Scanf("%f", &length) | |
input := length | |
var unit1, unit2 string | |
for { | |
fmt.Print("Введите единицу измерения: ") | |
fmt.Scanln(&unit1) | |
match := false | |
for _, unit := range unitNames { | |
if unit == unit1 { | |
match = true | |
} | |
} | |
if match { | |
break | |
} else { | |
fmt.Println("Я не знаю такой единицы, введите снова! ") | |
} | |
} | |
for { | |
fmt.Print("Введите единицу, в которую хотите перевести: ") | |
fmt.Scanln(&unit2) | |
match := false | |
for _, unit := range unitNames { | |
if unit == unit2 { | |
match = true | |
} | |
} | |
if match { | |
break | |
} else { | |
fmt.Println("Я не знаю такой единицы, введите снова! ") | |
} | |
} | |
for n, name := range unitNames { | |
if unit1 == name { | |
length = length * unitK[n] | |
} | |
} | |
for n, name := range unitNames { | |
if unit2 == name { | |
length = length / unitK[n] | |
} | |
} | |
fmt.Println(input, unit1, "=", length, unit2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment