示例#1
0
文件: cf.go 项目: k4rtik/gopl
func main() {
	for _, arg := range os.Args[1:] {
		t, err := strconv.ParseFloat(arg, 64)
		if err != nil {
			fmt.Fprintf(os.Stderr, "cf: %v\n", err)
			os.Exit(1)
		}
		f := tempconv.Fahrenheit(t)
		c := tempconv.Celsius(t)
		fmt.Printf("%s = %s, %s = %s\n", f, tempconv.FToC(f), c, tempconv.CToF(c))
	}
}
示例#2
0
文件: uc.go 项目: k4rtik/gopl
func main() {
	input := strings.Join(os.Args[1:], " ")
	if len(os.Args) == 1 {
		iscanner := bufio.NewScanner(os.Stdin)
		iscanner.Scan()
		input = iscanner.Text()
	}
	for _, arg := range strings.Split(input, " ") {
		t, err := strconv.ParseFloat(arg, 64)
		if err != nil {
			fmt.Fprintf(os.Stderr, "unitconv: %v\n", err)
			os.Exit(1)
		}
		f := tempconv.Fahrenheit(t)
		c := tempconv.Celsius(t)
		ft := unitconv.Feet(t)
		m := unitconv.Meters(t)
		p := unitconv.Pounds(t)
		k := unitconv.Kilograms(t)
		fmt.Printf("%s = %s, %s = %s\n", f, tempconv.FToC(f), c, tempconv.CToF(c))
		fmt.Printf("%s = %s, %s = %s\n", ft, unitconv.FToM(ft), m, unitconv.MToF(m))
		fmt.Printf("%s = %s, %s = %s\n", p, unitconv.PToK(p), k, unitconv.KToP(k))
	}
}