Simple Turing Number Game
Author |
Message |
xSavage
|
Posted: Wed Oct 28, 2015 6:29 pm Post subject: Simple Turing Number Game |
|
|
What is it you are trying to achieve?
So, I need help with the overall body of the code. The game I've been trying to make chooses a random number, and the user has to try to guess this number in 10 tries.
What is the problem you are having?
The problem is that the number changes each guess.
Describe what you have tried to solve this problem
So far I haven't had any success solving this problem.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
var num : int
var guess : int
var font1 := Font.New ("Comicsans:14:bold,italic")
Font.Draw ("Welcome to the Number Game!", 200, 300, font1, red)
locate(9, 20) color (green)
put "Instructions: The point of the game is to correctly"
locate(10, 22)
put "guess the number generated by the computer."
locate(11, 22)
put "You have a total of 10 guesses, good luck!"
locate(13, 35)
put "Creator: Marko M*****"
locate(25, 1)
put "Press any key to begin!"
Input.Pause()
cls
for k : 1 .. 10
randint (num, 1, 1000)
put "Please put in a number"
get guess
if guess>num then
put "Lower."
elsif guess<num then
put "Higher."
elsif guess=num then
put "Correct!"
end if
end for
|
Please specify what version of Turing you are using
I am using Turing version 4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
xSavage
|
Posted: Wed Oct 28, 2015 6:32 pm Post subject: RE:Simple Turing Number Game |
|
|
Obviously the code isn't anywhere near done, but I still need help. |
|
|
|
|
|
Filipe_rei_123
|
Posted: Wed Oct 28, 2015 8:08 pm Post subject: Re: Simple Turing Number Game |
|
|
Hi, Your issue is easy to fix on the basis of getting your program to work. But to make it able to get the number is 10 guesses is a bit more difficult but for now i can supply you with the code that makes the program work, ill just leave you with the objective of getting it to give you only 10 chances.
Code:
var hidden, guess : int
var reply : string (1)
put "See if you can guess the hidden number"
put "It is between 1 and 99 inclusive"
loop
var count : int := 0
put "Do you want to play? Answer y or n " ..
get reply
exit when reply = "n"
% Choose a random number between 1 and 99
randint (hidden, 1, 99)
loop
put "Enter your guess ",
"(any number between 1 and 99) " ..
get guess
count := count + 1
if guess < hidden then
put "You are low"
elsif guess > hidden then
put "You are high"
else
put "You got it in ", count, " guesses"
exit
end if
end loop
end loop |
|
|
|
|
|
xSavage
|
Posted: Wed Oct 28, 2015 8:33 pm Post subject: Re: Simple Turing Number Game |
|
|
Filipe_rei_123 @ Wed Oct 28, 2015 8:08 pm wrote: Hi, Your issue is easy to fix on the basis of getting your program to work. But to make it able to get the number is 10 guesses is a bit more difficult but for now i can supply you with the code that makes the program work, ill just leave you with the objective of getting it to give you only 10 chances.
Code:
var hidden, guess : int
var reply : string (1)
put "See if you can guess the hidden number"
put "It is between 1 and 99 inclusive"
loop
var count : int := 0
put "Do you want to play? Answer y or n " ..
get reply
exit when reply = "n"
% Choose a random number between 1 and 99
randint (hidden, 1, 99)
loop
put "Enter your guess ",
"(any number between 1 and 99) " ..
get guess
count := count + 1
if guess < hidden then
put "You are low"
elsif guess > hidden then
put "You are high"
else
put "You got it in ", count, " guesses"
exit
end if
end loop
end loop
OK, thanks Filipe, that was very helpful! Using what you gave me i managed to get to this code:
var num : int
var guess : int
var font1 := Font.New ("Comicsans:14:bold,italic")
var i : int := 0
var continuegame: string
Font.Draw ("Welcome to the Number Game!", 200, 300, font1, red)
locate(9,20) color (green)
put "Instructions: The point of the game is to correctly"
locate(10,22)
put "guess the number generated by the computer."
locate(11,22)
put "You have a total of 10 guesses, good luck!"
locate(13,35)
put "Creator: Marko Medic"
locate(25,1)
put "Press any key to begin!"
Input.Pause()
cls
loop
randint (num, 1, 1000)
loop
put "Please put in a number"
get guess
i := i+1
if guess>num then
put "Lower."
elsif guess<num then
put "Higher."
elsif guess=num then
put "Correct!"
end if
exit when guess=num or i=10
end loop
if guess=num then
put "Congratulations. You won the game!"
else
put "Sorry. You ran out of tries."
end if
put "Would you like to play again?"
get continuegame
exit when ((continuegame<>'Y') and (continuegame<>'y'))
end loop
This program works for the most part, although there is an error. I get a warning message that highlights this part: exit when ((continuegame<>'Y') and (continuegame<>'y'))
Any thoughts on how to fix this?
Thanks! |
|
|
|
|
|
Insectoid
|
Posted: Wed Oct 28, 2015 11:59 pm Post subject: RE:Simple Turing Number Game |
|
|
Quote: continuegame<>'Y'
Maybe this just didn't copy/paste to the site properly, but <> is not valid Turing code. I'm guessing you mean 'not=', which works fine and should solve the problem.
Usually when you get an error you don't 'just get an error'. Turing will give you an error message at the bottom of the screen that tells you what went wrong and maybe give you a hint about how to fix it. |
|
|
|
|
|
xSavage
|
Posted: Thu Oct 29, 2015 6:23 am Post subject: Re: RE:Simple Turing Number Game |
|
|
Insectoid @ Wed Oct 28, 2015 11:59 pm wrote: Quote: continuegame<>'Y'
Maybe this just didn't copy/paste to the site properly, but <> is not valid Turing code. I'm guessing you mean 'not=', which works fine and should solve the problem.
Usually when you get an error you don't 'just get an error'. Turing will give you an error message at the bottom of the screen that tells you what went wrong and maybe give you a hint about how to fix it.
Thanks a lot! That fixed it! I didn't realize it wasn't actually valid, my teacher told me to do it like that, so I just assumed it was correct. Once again, thanks alot! |
|
|
|
|
|
|
|