diff options
| author | Cody <cody@codyq.dev> | 2023-02-27 12:14:16 -0600 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2023-02-27 12:14:16 -0600 |
| commit | e4199d2837d2179f17e97b8d50366d96c8babded (patch) | |
| tree | e07543001ba1aa7e05ff8b289b4d3154d7123fd6 /examples/guessing.sloth | |
| parent | f464fe944808df7865262962b8231c0009874692 (diff) | |
| download | sloth-e4199d2837d2179f17e97b8d50366d96c8babded.tar.gz | |
Added while loops & guessing game
Diffstat (limited to 'examples/guessing.sloth')
| -rw-r--r-- | examples/guessing.sloth | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/guessing.sloth b/examples/guessing.sloth new file mode 100644 index 0000000..5d69944 --- /dev/null +++ b/examples/guessing.sloth @@ -0,0 +1,26 @@ +val computer = random(1, 10); + +var tries = 0; +var correct = false; + +while !correct { + print("\nPick a number between 1 and 5: "); + val human = 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; +} + +println("\nIt took you ", tries, " tries to guess correctly!"); |
