Add some comments.

This commit is contained in:
Jonathan Harker 2021-03-03 17:17:39 +13:00
parent d569d86790
commit 16ca18d8d1

View file

@ -11,9 +11,12 @@ const double internalInjuries = 25.0;
const double fatal = 40.0; const double fatal = 40.0;
const double puree = 100.0; const double puree = 100.0;
const Acceleration g = 9.8 * metre / second /second; // about 35.3 km/h/s const Acceleration g = 9.8 * metre / second / second; // about 35.3 km/h/s
const Mass typicalHuman = 80 * kilogram; const Mass typicalHuman = 80 * kilogram;
/++
+ Prompt the user for a plausible number from stdin.
+/
double getVelocity() { double getVelocity() {
string v = ""; string v = "";
while (!isNumeric(v)) { while (!isNumeric(v)) {
@ -24,6 +27,7 @@ double getVelocity() {
} }
void main(string[] argv) { void main(string[] argv) {
// Fetch a number from a cli argument, or prompt for one from stdin.
double velocity = 0; double velocity = 0;
auto args = getopt(argv, auto args = getopt(argv,
"velocity|v", "How fast The Flash was going", &velocity "velocity|v", "How fast The Flash was going", &velocity
@ -43,6 +47,7 @@ void main(string[] argv) {
Force f = typicalHuman * a; Force f = typicalHuman * a;
double accel_g = a / g; double accel_g = a / g;
// Output some opinionated results.
writefln("The Flash goes from stand-still to %s in a tenth of a second, thus accelerating at %.1f g.", "%.0f km/h".siFormat(v), accel_g); writefln("The Flash goes from stand-still to %s in a tenth of a second, thus accelerating at %.1f g.", "%.0f km/h".siFormat(v), accel_g);
writefln("This would exert a force of %s on a typical human body.", "%.1f kN".siFormat(f)); writefln("This would exert a force of %s on a typical human body.", "%.1f kN".siFormat(f));