aboutsummaryrefslogtreecommitdiff
path: root/examples/guessing.sloth
blob: ef680c9966ab1dbddd732ece065880cfb0044e3d (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
fn main() Int {
	var computer: Int = randGen(1, 10);
	var tries: Int = 0;
	var correct: Bool = false;

	while correct == false {
		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;
	}

	print("It took you ");
	var s: String = istr(tries);
	print(s);
	println(" to guess correctly!");

	return 0;
}