August 03, 2012 Re: How to use "read_bool"? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Friday, 3 August 2012 at 19:25:21 UTC, Ali Çehreli wrote:
> On 08/03/2012 12:17 PM, Philippe Sigaud wrote:
>
> > some of us could start a 2nd level translation (japanese, russian, italian, german and french are likely possibilities).
>
> How timely! Crimson Sphere has just started the Korean translation:
>
> http://p-crimsonsphere.blogspot.kr/p/programming-in-d.html
>
> The "Hello World" chapter has some recognizable code: :)
>
> http://p-crimsonsphere.blogspot.kr/2012/08/hello-world.html
Ouch those pages just hurt my eyes. I had enough of the Korean language when I was in Korea.
However it is a good thing it's getting translated and more coverage; I just hope most of the comments (and code) stay in english since it's kinda de-facto for most computer languages.
|
August 04, 2012 Re: How to use "read_bool"? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zeh | Thanks for the help, but i tryed both solutions posted and still not working. :/ I get erros to compile the code posted by simendsjo. I try modify at my own, but without success. The code suggest by Timon Gehr compiles, but not work. Honestly speaking, i didn't have enough knowledge to understand the solutions offered (yet). What is the smallest way to use the "read_bool"? Besides, one version of that tutorial in portuguese would be great =D |
August 04, 2012 Re: How to use "read_bool"? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zeh | On Sat, 04 Aug 2012 03:01:31 +0200, Zeh <zecacu@yahoo.com.br> wrote:
> Thanks for the help, but i tryed both solutions posted and still not working. :/
>
> I get erros to compile the code posted by simendsjo. I try modify at my own, but without success. The code suggest by Timon Gehr compiles, but not work.
>
> Honestly speaking, i didn't have enough knowledge to understand the solutions offered (yet). What is the smallest way to use the "read_bool"?
>
>
> Besides, one version of that tutorial in portuguese would be great =D
This works:
import std.stdio, std.string, std.conv;
bool read_bool(in string message) {
while(true) {
write(message, " (false or true): ");
string input;
do {
input = readln().chomp();
} while(!input.length);
writeln("INPUT: '", input, "'");
try
return input.to!bool();
catch {}
}
}
void main() {
write("How many are we? ");
int personCount;
readf(" %s", &personCount);
write("How many bicycles are there? ");
int bicycleCount;
readf(" %s", &bicycleCount);
write("What is the distance to the beach? ");
int distance;
readf(" %s", &distance);
bool existsCar = read_bool("Is there a car? ");
bool existsLicense =
read_bool("Is there a driver license? ");
}
$ rdmd read_bool
How many are we? 10
How many bicycles are there? 1
What is the distance to the beach? 2
Is there a car? (false or true): true
Is there a driver license? (false or true): false
|
August 06, 2012 Re: How to use "read_bool"? | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo | On Saturday, 4 August 2012 at 08:35:36 UTC, simendsjo wrote:
> On Sat, 04 Aug 2012 03:01:31 +0200, Zeh <zecacu@yahoo.com.br> wrote:
>
>> Thanks for the help, but i tryed both solutions posted and still not working. :/
>>
>> I get erros to compile the code posted by simendsjo. I try modify at my own, but without success. The code suggest by Timon Gehr compiles, but not work.
>>
>> Honestly speaking, i didn't have enough knowledge to understand the solutions offered (yet). What is the smallest way to use the "read_bool"?
>>
>>
>> Besides, one version of that tutorial in portuguese would be great =D
>
>
> This works:
> import std.stdio, std.string, std.conv;
>
> bool read_bool(in string message) {
> while(true) {
> write(message, " (false or true): ");
> string input;
> do {
> input = readln().chomp();
> } while(!input.length);
> writeln("INPUT: '", input, "'");
>
> try
> return input.to!bool();
> catch {}
> }
> }
>
> void main() {
> write("How many are we? ");
> int personCount;
> readf(" %s", &personCount);
>
> write("How many bicycles are there? ");
> int bicycleCount;
> readf(" %s", &bicycleCount);
>
> write("What is the distance to the beach? ");
> int distance;
> readf(" %s", &distance);
>
> bool existsCar = read_bool("Is there a car? ");
> bool existsLicense =
> read_bool("Is there a driver license? ");
> }
>
>
> $ rdmd read_bool
> How many are we? 10
> How many bicycles are there? 1
> What is the distance to the beach? 2
> Is there a car? (false or true): true
> Is there a driver license? (false or true): false
Very interesting way to solve the problem (at least for a noobie
like me ^^ ). Thanks for the help!
|
August 06, 2012 Re: How to use "read_bool"? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zeh | On 08/04/2012 03:01 AM, Zeh wrote:
> Thanks for the help, but i tryed both solutions posted and still not
> working. :/
>
> I get erros to compile the code posted by simendsjo. I try modify at my
> own, but without success. The code suggest by Timon Gehr compiles, but
> not work.
>
Works for me. Maybe readln behaves differently on windows?
|
Copyright © 1999-2021 by the D Language Foundation