Advertisement
Spocoman

Metric Converter

Oct 10th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.67 KB | None | 0 0
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6.     var number float64
  7.     fmt.Scanln(&number)
  8.    
  9.     var inputMetric, outputMetric string
  10.     fmt.Scanln(&inputMetric)
  11.     fmt.Scanln(&outputMetric)
  12.  
  13.     if inputMetric == "mm" {
  14.         if outputMetric == "cm" {
  15.             number /= 10
  16.         } else {
  17.             number /= 1000
  18.         }
  19.     } else if inputMetric == "cm" {
  20.         if outputMetric == "m" {
  21.             number /= 100
  22.         } else {
  23.             number *= 10
  24.         }
  25.     } else {
  26.         if outputMetric == "cm" {
  27.             number *= 100
  28.         } else {
  29.             number *= 1000
  30.         }
  31.     }
  32.  
  33.     fmt.Printf("%.3f", number)
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement