From 8f31e77e965f432f2b4c7a301116d83b35068a67 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 17 Oct 2012 23:57:27 -0400 Subject: [PATCH] Doing unit conversion prog, touching up Makefile --- d/prog-lang-book/Makefile | 4 +++- d/prog-lang-book/src/height_conversions.d | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 d/prog-lang-book/src/height_conversions.d diff --git a/d/prog-lang-book/Makefile b/d/prog-lang-book/Makefile index 2e26faa..95c7edd 100644 --- a/d/prog-lang-book/Makefile +++ b/d/prog-lang-book/Makefile @@ -4,4 +4,6 @@ ALL_TARGETS := $(patsubst src/%.d,bin/%,$(ALL_SOURCES)) bin/%: src/%.d dmd $^ -of$@ -$(ALL_TARGETS): $(ALL_SOURCES) +all: $(ALL_TARGETS) + +.PHONY: all diff --git a/d/prog-lang-book/src/height_conversions.d b/d/prog-lang-book/src/height_conversions.d new file mode 100644 index 0000000..63dbbda --- /dev/null +++ b/d/prog-lang-book/src/height_conversions.d @@ -0,0 +1,19 @@ +/* + Compute heights in centimeters for a range of heights + expressed in feet and inches + */ +import std.stdio; + +void main() { + // Values unlikely to change soon + immutable inchesPerFoot = 12; + immutable cmPerInch = 2.54; + + // Loop'n write + foreach (feet; 5 .. 7) { + foreach (inches; 0 .. inchesPerFoot) { + writeln(feet, "'", inches, "''\t", + (feet * inchesPerFoot + inches) * cmPerInch); + } + } +}