This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
herty75's profile picture

Error in my program ...

Started by herty75, 26 September 2016 - 10:00 PM
herty75 #1
Posted 27 September 2016 - 12:00 AM
Hey guys ! I have problem in my program ! Can you help me !



do
	numb = math.random(1,100)
	tries = 1
	triesmax = 7
	guess = 0
end


do
	term.clear()
	textutils.slowPrint(Trouve le chiffre par Herty75)
	print(Entrée pour continuer)
	io.read()
	print(Tu as 6 chance pour trouver le bon chiffre!)
end


while (tries =< triesmax) do
	   print(devine un chiffre entre. [1 - 100, nombre entier])
		guess = io.read()
		guess = tonumber(guess)
		if guess == numb then
			print(Winner: Joueur)
			tries = triesmax
		elseif guess > numb then
				print(Ton chiffre est trop haut!)
			 else
				print(Ton chiffre est trop bas!)
			 end
		 end
			tries = tries + 1
end

do
	term.clear()
	textutils.slowPrint(Tu peux relancer!)
end



Ty !
KingofGamesYami #2
Posted 27 September 2016 - 12:39 AM
To print something to the screen, it has to be a string. To make a string, surround some words in quotation marks.


print( "Hello, World!" )

Also, your code doesn't have to be (and probably shouldn't be) surrounded by do … end statements. The do / end combination used with the while loop is necessary and serves a purpose, the other three do not.
Sewbacca #3
Posted 27 September 2016 - 06:47 PM
Your program allows 7 not 6 tries, because 7 >= 7.
Also, you could use a for statement instead of a while statement:

for try = 1, 6 do
  <CODE>
end
Edited on 27 September 2016 - 08:20 PM
Dog #4
Posted 27 September 2016 - 07:17 PM
I may be mistaken, but it looks like you have an extra end just before tries = tries + 1.