Jump to content




Error in my program ...



  • You cannot reply to this topic
3 replies to this topic

#1 herty75

  • New Members
  • 1 posts

Posted 26 September 2016 - 11:00 PM

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 !

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 26 September 2016 - 11:39 PM

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.

#3 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 27 September 2016 - 05: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 by Sewbacca, 27 September 2016 - 09:20 PM.


#4 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 27 September 2016 - 06:17 PM

I may be mistaken, but it looks like you have an extra end just before tries = tries + 1.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users