Computer Science Canada Editing a code, Trying to add a replay y/n option - Need help |
Author: | Aange10 [ Sat Sep 03, 2011 2:12 pm ] | ||||
Post subject: | Editing a code, Trying to add a replay y/n option - Need help | ||||
What is it you are trying to achieve? I have just started learning turing, and I have read a lot of the time the best way to learn is to look at other people's code and edit/add to the code. I went to the 20 lines or less weekly contest (I figured very good programers would be there, with short code that I could understand, and little "extra features". Allowing me to add these "extra features") and I found a nice random triangle drawing code, and wanted to add a replay button to it. What is the problem you are having? I have successfully (and probably messily) added a way to replay. However I can not find out how to "bug proof" the y/n system. Describe what you have tried to solve this problem I have tried adding another else statement that tells them that what they have entered is an invalid letter, and makes them choose another. My coding (probably messily) works! But the only problem is if they enter an invalid character again, it will just act as if they pressed "y" (except it doesn't clear the screen). Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) The origional code is:
The code now (after my adding) looks like this:
Please specify what version of Turing you are using 4.1.1 |
Author: | Insectoid [ Sat Sep 03, 2011 2:20 pm ] | ||
Post subject: | RE:Editing a code, Trying to add a replay y/n option - Need help | ||
You're going in the right direction. In order to 'bug proof' your system, you can put the prompt into another loop.
|
Author: | Aange10 [ Sat Sep 03, 2011 2:29 pm ] | ||||
Post subject: | RE:Editing a code, Trying to add a replay y/n option - Need help | ||||
Thankyou, insectoid! However, y does clear the screen and then repeat the loop. (So the triangles won't be drawn over each other) So would
work? EDIT: This code works, thank you a ton for assisting me!
|
Author: | Insectoid [ Sat Sep 03, 2011 2:58 pm ] | ||
Post subject: | RE:Editing a code, Trying to add a replay y/n option - Need help | ||
Better to cls at the top of the main loop. It will perform the same, but it's good coding practice. The program flow should look like this:
It's important that your code is organized. |