aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorNic Gaffney <gaffney_nic@protonmail.com>2023-06-28 15:21:54 -0500
committerNic Gaffney <gaffney_nic@protonmail.com>2023-06-28 15:21:54 -0500
commit7d14243f769ad911d7c057b891ed89a95d7c1bfd (patch)
treea64f621b49b7e0c2199eac406e8ca21fdc6b174e /examples
parent00f695f1fd38e79c60cb8b37f90708a2186a42e8 (diff)
downloadsloth-7d14243f769ad911d7c057b891ed89a95d7c1bfd.tar.gz
added istr to std
Diffstat (limited to 'examples')
-rw-r--r--examples/guessing.sloth14
1 files changed, 10 insertions, 4 deletions
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;
}