About Me

Ontario, Canada
In regards to this blog, I am simply trying to learn to program in my free hours after work in order to make an iPhone game.

Saturday, May 9, 2009

Repeat After Me

Ok, so since I have not been reading much lately due to being sick I figure I can post a short piece of code that I had previously written to show you what kind of level I am at.

So, first, the code (it is in an image format since when I use the 'code' function in here the formatting goes to shit).



This is simply one piece of a 5 part code, though this piece represents, almost exactly, what happens later on.

Basically this program tells the user to repeat after it using the correct keys.

It tells the user to type every number it says in numerals. ie. ONE = 1

(the program goes up to the number 5, since the code is redundant, there was no need to keep going as the ideas behind it are easily learned from the first few instances)

The fun of writing this program though was figuring out how to take the users WRONG answer and allow them to try again, and again, and again, and then continuing on with the program when they finally get it right.

Obviously it is very hard to screw up 1, 2, 3, 4, 5 but the ideas behind it hold true. Being able to take a wrong answer and allowing the user to try once more. ie. error checking, so to speak.

Another part of the fun of writing this program was the fact that I was still very green on how do/while loops worked so it was very pleasing when it finally worked just right. I had some looping issues with certain areas not being displayed properly, or areas being printed twice in a row. The fix for that was making sure I was using the 'fpurge' function after each 'getchar' function.

Alright, so that is that.

Cheers! :D

No comments:

Post a Comment