From 7d14243f769ad911d7c057b891ed89a95d7c1bfd Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Wed, 28 Jun 2023 15:21:54 -0500 Subject: added istr to std --- examples/guessing.sloth | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/guessing.sloth b/examples/guessing.sloth index 5a759e5..f88c35b 100644 --- a/examples/guessing.sloth +++ b/examples/guessing.sloth @@ -3,13 +3,15 @@ foreign fn println(); foreign fn readln() String; foreign fn random(min: Int, max: Int) Int; foreign fn parse_int(str: String) Int; +foreign fn randGen(min: Int, max: Int) Int; +foreign fn istr(x: Int) String; -fn main() { - var computer: Int = random(1, 10); +fn main() Int { + var computer: Int = randGen(1, 10); var tries: Int = 0; var correct: Bool = false; - while !correct { + while correct == false { print("Pick a number between 1 and 10: "); var human: Int = parse_int(readln()); @@ -25,5 +27,9 @@ fn main() { tries = tries + 1; } - println("It took you ", tries, " tries to guess correctly!"); + print("It took you "); + print(istr(tries)); + println(" to guess correctly!"); + + return 0; } -- cgit v1.2.3