Computer Science Canada Indent Problem on Guessing Game |
Author: | dhyanp11 [ Mon Feb 29, 2016 10:05 pm ] |
Post subject: | Indent Problem on Guessing Game |
loop % var Font : int % Font := Font.New ("courier :10) % Font.Draw ("Guess the Number!", 10, 475, Font, black) % Draw.Box (5, 468, 215, 497, black) var l : int := Rand.Int (1, limit) % Generates the number that the user is trying to guess Text.Locate (5, 1) put "Guess the number! It's between 1 and 100." loop loop get input if strintok (input) then z := strint (input) exit else put "That's not a number!" delay (1000) clearall Text.Locate (5, 1) put "Guess the number! It's between 1 and 100." end if end loop if z = l then put "Congratulations! You guessed correctly!" exit else if z > l then put "Try guessing lower. Keep on going." else if z < l then put "Try guessing higher. Keep on going." end if put "It took you " .. put counter .. put " guesses to guess the correct number!" if counter = 1 then put "Start buying lottery tickets!" else if counter <= 3 then put "You are an AI!" else if counter <= 6 then put "Great guessing! Move up to the next level to challenge yourself." else if counter <= 10 then put "Try guessing the number faster next time." else if counter >= 10 then put "Use better guessing strategies next time." end if end loop delay (1000) put "" put "Want to play again? y/n" get yesorno if yesorno = "n" then % if user chooses not to play again put "" put "You have decided to quit, Peace!" delay (1000) exit else if yesorno = "y" then % if user chooses to play again put "" put "You have chosen to play again!" delay (1000) clearall else % Makes user play again if they do not enter either a 'y' or a 'n put "" put "Assuming that as play again" delay (1000) clearall end if end loop Keep on getting syntax error at end loop, expected end loop. I think it is a problem with indentation. Any suggestions would be helpful. Feel free to alter the code. |
Author: | Dreadnought [ Tue Mar 01, 2016 2:08 pm ] | ||||||
Post subject: | Re: Indent Problem on Guessing Game | ||||||
It seems you are writing
instead of
The difference is that in the first case you need an extra end if to close the nested if statement that you began after else. Also to make you code easier to read on this forum you can wrap in as follows
|