Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.93 KB | None | 0 0
  1. import rdstdin
  2. import random
  3. import strutils
  4. import strformat
  5. import os
  6.  
  7. echo "Guessing Game in Nim\n------------------------"
  8.  
  9. randomize()
  10. let number = random.rand(1..10)
  11. var cont = true
  12. var count = 5
  13. proc input(): int =
  14.     try:
  15.         result = parseInt(rdstdin.readLineFromStdin(
  16.                 fmt "\nguess the number ({count} chances left) :"))
  17.     except ValueError:
  18.         echo "wrong input"
  19.         result = -1
  20.     count -= 1
  21.  
  22. proc flow(): void =
  23.     var guessed = input()
  24.     if guessed == -1:
  25.         echo "Moron"
  26.     elif guessed < number:
  27.         echo fmt "{guessed} is too small"
  28.     elif guessed > number:
  29.         echo fmt "{guessed} is too big"
  30.     else:
  31.         echo "you guessed it correctly"
  32.         cont = false
  33.  
  34. while cont and count > 0:
  35.     flow()
  36. if count == 0 and cont == false:
  37.     echo fmt "\nfailed: you have used all your chances\nThe number is {number}"
  38. discard os.execShellCmd("pause")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement