posted 7 years ago
hello everyone i try to learn Erlang otp programing and i have such a problem how to solve this task i try but i'm new and i don't have a good background on programing any suggestion!!
Implement a function that generates a random integer between 1 and 100. Then it reads an integer number from the standard input and checks whether the user given number is equal to the generated number. If not than it provides some hints to the user (similar to: "The number is lesser than ... ", "The number is greater than ...") and asks for a new number. The function asks numbers recursively until the user hits the generated one. To avoid infinite recursion a limit is provided as an initial argument, that is the maximum numbers of attempts. Please read the examples carefully to see what is the required information to provide for the user.
Example 1:
1> generate:num(20)
#########
Guess a number between 1 and 100!
--> 22.
22 is not my number. It is lesser than 22.
#########
Guess a number between 1 and 21!
--> 2.
2 is not my number. It is greater than 2.
#########
Guess a number between 3 and 21!
--> 5.
#########
Oh, yeah! 5 is my number! You've won the game!
Example 2:
1> generate:num(2)
#########
Guess a number between 1 and 100!
--> 55.
55 is not my number. It is lesser than 55.
#########
Guess a number between 1 and 54!
--> 21.
21 is not my number. It is lesser than 21.
#########
Game is over, sorry you've lost the game!