Computer Science Canada Game List Organiser |
Author: | vertdragon23 [ Wed Dec 11, 2013 11:29 pm ] | ||
Post subject: | Game List Organiser | ||
What is it you are trying to achieve? I am trying to make a program that reads data from a text file (game made in 1995) and then sorts it, so that user can enter in something like 1995, and it will show them all games made that year. What is the problem you are having? I have no idea how to get started. Need a kickstarter. Describe what you have tried to solve this problem Coming to comp sci. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using <4.1.1 (latest)> |
Author: | Raknarg [ Thu Dec 12, 2013 10:27 am ] |
Post subject: | RE:Game List Organiser |
First of all, do you know how to make arrays? You can start by putting them all into one array. |
Author: | vertdragon23 [ Thu Dec 12, 2013 1:01 pm ] |
Post subject: | RE:Game List Organiser |
how would I get line by line and put into array, so that user can search. http://gyazo.com/e16a353421bb250786b54dca87b8c158 |
Author: | Raknarg [ Thu Dec 12, 2013 5:04 pm ] | ||||||||||
Post subject: | Re: Game List Organiser | ||||||||||
Go at it piece by piece. Because you know how it's organized, it makes things much simpler. What you can do is put each type of info into an array, like so (don't worry about the flexibl part, I'll get to that in a minute)
What this does is create a bunch of arrays whose size you can change. It starts at 0 so you can add information whenever you need to. Before we go on though, this is really ugly, there's too many arrays to deal with. You can condense this all into one array like this:
See what I did there? Is is what's called a "record" in Turing, or sometimes it's known as a structure in other languages like Visual Basic. Basically you tell it all the variable types you want to have, and every variable of that type will have all that info in it. This organizes your info and reduces redundant code and clutter. You can call the variables like this:
Now I'll tell you about the flexible part. Usually arrays are immutable in size, so if you make it 10 elements long, you can't change it. However, with a flexible array you can, as such:
Now Think about this: We know that each row will always have enough info for the game, genre, developer, etc. So we can just do smething like this:
And we're done! Hope this helps. If this is confusing, just ask. Note that this stuff can all be found in the Turing Walkthrough. |
Author: | vertdragon23 [ Thu Dec 12, 2013 7:29 pm ] |
Post subject: | RE:Game List Organiser |
I get the error (attempted to read past EOF).. Your lesson was very helpful by the way. procedure reading type gameDataTypes : record Game, Genre, Developer, Release, Sales, Price : string end record var gameInfo : flexible array 1 .. 0 of gameDataTypes var someGame : gameDataTypes someGame.Game:= "Super Fun Game" someGame.Genre:= "Awesome" someGame.Developer:= "Ultra Cool Studios" var stream:int open : stream, "Wiigames.txt", get loop exit when eof(stream) new gameInfo, upper (gameInfo) + 1 get : stream,gameInfo(upper(gameInfo)).Game end loop close: stream end reading |
Author: | Raknarg [ Thu Dec 12, 2013 8:35 pm ] | ||
Post subject: | RE:Game List Organiser | ||
1) var someGame : gameDataTypes someGame.Game:= "Super Fun Game" someGame.Genre:= "Awesome" someGame.Developer:= "Ultra Cool Studios" That stuff was just for an example, you don't actually need those things for this to work 2) Why is all this stuff listed inside your reading procedure? Just so you know, if you create variables or records inside of a procedure, you can only use them inside the procedure. If you want to use them through your whole program, you need to do something like this:
Notice how I make that stuff outside the procedure? Now I can use them wherever I want in the program, not just in the procedure 3)get : stream,gameInfo(upper(gameInfo)).Game Just so you know, you need to do this for every one of the variables inside your record. This right now is just changing the game part of that record. Think about this: First run through, it calls up Sports, and puts that on gameInfo(1).game. It goes through the loop. It increases the gameInfo array by 1. Now it calls up Sports (next thing in the text file). It assigns that to gameInfo(2).game. You don't want that. You want the game assigned to the game part of the record, then the genre assigned to the genre part of the record, and so on. Remember that each row of the text file is like on item in the array. Each row has info for the game, genre, developer, etc., and your record has info for all tose things too. Make sure they're all being assigned to the right spot. 4) Im looking at the screenshot of your text file. Make sure it does NOT contain the column headers or all those dashes, unless you know what you're doing with them 5) Is this all your code? I can't see any reason why your code would be giving you an eof |