-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexbeachlogic.d
50 lines (40 loc) · 1.17 KB
/
exbeachlogic.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import std.stdio;
import std.conv;
import std.string;
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's license?: ");
/*
Replace the ' true ' below with a logica expression
that produces the value ' true ' when one of the
conditions listed in the question is satisfied.
*/
writeln("We are going to the beach: ",
(distance < 10 && bicycleCount == personCount) ||
personCount < 6 && (existsCar == true && existsLicense == true)
);
}
bool read_bool(string message)
{
// Print the message
write(message, "(false or true) ");
// Read the line as a string
string input;
while (input.length == 0) {
input = chomp(readln());
}
// Produce a 'bool' value from that string
bool result = to!bool(input);
// Return the result to the caller
return result;
}