[your code here]
Jonathan M Davis
jmdavisProg at gmx.com
Fri Feb 17 18:24:10 PST 2012
On Friday, February 17, 2012 21:03:43 Matt Soucy wrote:
> On 02/17/2012 08:13 PM, Jonathan M Davis wrote:
> > On Friday, February 17, 2012 18:50:32 Matt Soucy wrote:
> >> #!/usr/bin/rdmd
> >> import std.stdio;
> >> void main()
> >> {
> >> uint guesses=0, high=100, low=0, guess=50;
> >> char returned;
> >> writef("Please choose a number between %s and %s.\n");
> >> writef("Press enter to begin.",low,high);
> >> readln();
> >> checkLoop:
> >> do {
> >> guess = (high-low)/2+low; // Avoid overflow (shouldn't occur)
> >> writef("Is your number %s? [(y)es, (h)igher, (l)ower] ", guess);
> >> readf("%c",&returned);
> >> readln();
> >> switch(returned) {
> >> case 'y','Y': break checkLoop;
> >> case 'h','H': {low=guess; break;}
> >> case 'l','L': {high=guess; break;}
> >> default: break;
> >> }
> >> } while(++guesses);
> >> writef("I guessed your number in %s moves!\n", guesses);
> >> }
> >>
> >>
> >> This piece is something I wrote quickly for /r/dailyprogrammer (By the
> >> way, is the person who has been posting D solutions to that on here?)
> >> It's a really simple piece, but it shows %s, breaking from a loop from
> >> inside a switch, etc.
> >
> > Shouldn't it be dmd and not rdmd in the first line?
> >
> > - Jonathan M Davis
>
> I chose rdmd because I wanted to demonstrate direct running it directly,
> not building it that way.
> Out of curiosity, though, is there a specific reason why I should have
> used dmd instead? Without switches, that would just build it...
As I understand it, you can run it as a script with #!/bin/dmd, and dmd is
guaranteed to be on your system if you're programming in D whereas rdmd might
not be.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list