Old Russian measure of length: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|C}}: Remove vanity tags) |
(Added Go) |
||
Line 461: | Line 461: | ||
Do another one y/n : ? n |
Do another one y/n : ? n |
||
</pre> |
|||
=={{header|Go}}== |
|||
{{trans|Kotlin}} |
|||
<lang go>package main |
|||
import ( |
|||
"bufio" |
|||
"fmt" |
|||
"os" |
|||
"strconv" |
|||
"strings" |
|||
) |
|||
func main() { |
|||
units := []string{ |
|||
"tochka", "liniya", "dyuim", "vershok", "piad", "fut", |
|||
"arshin", "sazhen", "versta", "milia", |
|||
"centimeter", "meter", "kilometer", |
|||
} |
|||
convs := []float32{ |
|||
0.0254, 0.254, 2.54, 4.445, 17.78, 30.48, |
|||
71.12, 213.36, 10668, 74676, |
|||
1, 100, 10000, |
|||
} |
|||
scanner := bufio.NewScanner(os.Stdin) |
|||
for { |
|||
for i, u := range units { |
|||
fmt.Printf("%2d %s\n", i+1, u) |
|||
} |
|||
fmt.Println() |
|||
var unit int |
|||
var err error |
|||
for { |
|||
fmt.Print("Please choose a unit 1 to 13 : ") |
|||
scanner.Scan() |
|||
unit, err = strconv.Atoi(scanner.Text()) |
|||
if err == nil && unit >= 1 && unit <= 13 { |
|||
break |
|||
} |
|||
} |
|||
unit-- |
|||
var value float64 |
|||
for { |
|||
fmt.Print("Now enter a value in that unit : ") |
|||
scanner.Scan() |
|||
value, err = strconv.ParseFloat(scanner.Text(), 32) |
|||
if err == nil && value >= 0 { |
|||
break |
|||
} |
|||
} |
|||
fmt.Println("\nThe equivalent in the remaining units is:\n") |
|||
for i, _ := range units { |
|||
if i == unit { |
|||
continue |
|||
} |
|||
fmt.Printf(" %10s : %g\n", units[i], float32(value)*convs[unit]/convs[i]) |
|||
} |
|||
fmt.Println() |
|||
yn := "" |
|||
for yn != "y" && yn != "n" { |
|||
fmt.Print("Do another one y/n : ") |
|||
scanner.Scan() |
|||
yn = strings.ToLower(scanner.Text()) |
|||
} |
|||
if yn == "n" { |
|||
return |
|||
} |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
Sample input/output: |
|||
<pre> |
|||
1 tochka |
|||
2 liniya |
|||
3 dyuim |
|||
4 vershok |
|||
5 piad |
|||
6 fut |
|||
7 arshin |
|||
8 sazhen |
|||
9 versta |
|||
10 milia |
|||
11 centimeter |
|||
12 meter |
|||
13 kilometer |
|||
Please choose a unit 1 to 13 : 13 |
|||
Now enter a value in that unit : 1 |
|||
The equivalent in the remaining units is: |
|||
tochka : 393700.78 |
|||
liniya : 39370.08 |
|||
dyuim : 3937.0078 |
|||
vershok : 2249.7188 |
|||
piad : 562.4297 |
|||
fut : 328.08398 |
|||
arshin : 140.60742 |
|||
sazhen : 46.86914 |
|||
versta : 0.9373828 |
|||
milia : 0.13391183 |
|||
centimeter : 10000 |
|||
meter : 100 |
|||
Do another one y/n : n |
|||
</pre> |
</pre> |
||