46 lines
925 B
Go
46 lines
925 B
Go
// Copyright © 2018 Inanc Gumus
|
|
// Learn Go Programming Course
|
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
//
|
|
// For more tutorials : https://learngoprogramming.com
|
|
// In-person training : https://www.linkedin.com/in/inancgumus/
|
|
// Follow me on twitter: https://twitter.com/inancgumus
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
func main() {
|
|
const (
|
|
EUR = iota
|
|
GBP
|
|
JPY
|
|
)
|
|
|
|
rates := [...]float64{
|
|
EUR: 0.88,
|
|
GBP: 0.78,
|
|
JPY: 113.02,
|
|
}
|
|
|
|
args := os.Args[1:]
|
|
if len(args) != 1 {
|
|
fmt.Println("Please provide the amount to be converted.")
|
|
return
|
|
}
|
|
|
|
amount, err := strconv.ParseFloat(args[0], 64)
|
|
if err != nil {
|
|
fmt.Println("Invalid amount. It should be a number.")
|
|
return
|
|
}
|
|
|
|
fmt.Printf("%.2f USD is %.2f EUR\n", amount, rates[EUR]*amount)
|
|
fmt.Printf("%.2f USD is %.2f GBP\n", amount, rates[GBP]*amount)
|
|
fmt.Printf("%.2f USD is %.2f JPY\n", amount, rates[JPY]*amount)
|
|
}
|