blob: 5a759e5b0282f968ebfce355e064e98b0afa81e4 (
plain)
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
|
foreign fn print();
foreign fn println();
foreign fn readln() String;
foreign fn random(min: Int, max: Int) Int;
foreign fn parse_int(str: String) Int;
fn main() {
var computer: Int = random(1, 10);
var tries: Int = 0;
var correct: Bool = false;
while !correct {
print("Pick a number between 1 and 10: ");
var human: Int = parse_int(readln());
if human == computer {
println("You guessed the same number as me!\n");
correct = true;
} else if human > computer {
println("Your guess was too high.\n");
} else if human < computer {
println("Your guess was too low.\n");
}
tries = tries + 1;
}
println("It took you ", tries, " tries to guess correctly!");
}
|