From def8adfcb9a9572f4e030990626a0d08377118bd Mon Sep 17 00:00:00 2001 From: Cody Date: Sat, 24 Jun 2023 21:11:44 -0500 Subject: hehehaha --- examples/guessing.sloth | 47 +++++++++++++++++++++++++---------------------- examples/hello.sloth | 2 ++ 2 files changed, 27 insertions(+), 22 deletions(-) (limited to 'examples') diff --git a/examples/guessing.sloth b/examples/guessing.sloth index 05c25db..5a759e5 100644 --- a/examples/guessing.sloth +++ b/examples/guessing.sloth @@ -1,26 +1,29 @@ -val computer: int = random(1, 10); +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; -var tries: int = 0; -var correct: bool = false; +fn main() { + var computer: Int = random(1, 10); + var tries: Int = 0; + var correct: Bool = false; -while !correct { - print("\nPick a number between 1 and 10: "); - val human: int = parse_int(readln()); + 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!"); - correct = true; - } - - if human > computer { - println("Your guess was too high."); - } - - if human < computer { - println("Your guess was too low."); - } - - tries = tries + 1; -} + 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("\nIt took you ", tries, " tries to guess correctly!"); + println("It took you ", tries, " tries to guess correctly!"); +} diff --git a/examples/hello.sloth b/examples/hello.sloth index 8b395e8..a955e66 100644 --- a/examples/hello.sloth +++ b/examples/hello.sloth @@ -1,3 +1,5 @@ +foreign fn example(arg: Int) Void; + fn main() { var i: Int = 10; var j: Int = 1.0 - 1; -- cgit v1.2.3