開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Go (プログラミング言語)
Head First Go (Jay McGavren(著)、O'Reilly Media)のChapter 1(let's get going - Syntax Basics)、Exercise(24)の解答を求めてみる。
コード
package main import "fmt" func main() { var price int = 100 fmt.Println("Price is", price, "dollars.") var taxRate float64 = 0.08 var tax float64 = float64(price) * taxRate fmt.Println("Tax is", tax, "dollars.") var total float64 = float64(price) + tax fmt.Println("Total cost is", total, "dollars.") var availableFunds int = 120 fmt.Println(availableFunds, "dollars available.") fmt.Println("Within budget?", float64(availableFunds) > total) }
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal)
$ go run sample4.go Price is 100 dollars. Tax is 8 dollars. Total cost is 108 dollars. 120 dollars available. Within budget? true $
0 コメント:
コメントを投稿