Computer Science Canada Nickname generator plz help |
Author: | Lancelot [ Tue Jul 19, 2005 2:38 pm ] |
Post subject: | Nickname generator plz help |
I have letters.txt with following data: bcdfghjklmnpqrstvwxyz aeiou I was thinking of making a nickname generator, so it will take first random letter from the first row, second random from the second row, third random from the first and so on... So, I am trying to use seek, but all I get is a bunch of random numbers instead of letters. It should be simple, but I am really lost with getting letters from the file. |
Author: | Cervantes [ Tue Jul 19, 2005 2:47 pm ] | ||||||
Post subject: | |||||||
Well, you don't have to use a file. It would be easier if you set up two constants, like so:
Actually, it would even work better if it were an array. That way you could use a for loop to get your letters.
But, if you really want to use a file, know that every time you use get the "cursor" jumps to the next line. So you could get a letter from the first line (you'd have to read the line into a variable first, though), get a letter from the second line, then seek back to the start, like this:
If that doesn't help, post the code you've got so far. ![]() |
Author: | Delos [ Tue Jul 19, 2005 3:55 pm ] |
Post subject: | |
As Cervantes as pointed out, you needn't use a file for this. But let's say that you wanted to use a file, and you found that the command 'seek' could be used for your purposes. This is all well and good, and Cervantes' method would likely work. However, this is by no means the best way of doing this. Rather, you could use your file as simply a data depository. Your programme would open the file, extract its contents, and then manipulate those contents in the form of variables (or as Cervantes pointed out, elements of an array). You should be familiar with opening and clos(e)ing files, as well as basic String Manipulation. Check the Tutorials if you need help with either of these topics. Again, it is customary for one to post their code when asking a question. This helps us to see how much you know, and to accertain the nature of your problem as quickly as possible. When posting code, please use either [code] or [syntax] tags. If your code is particularly long, attach it instead. Post your solution when you're done, I'd like to see how you tackle this. Edit: Just realized your Join Date...woah! ![]() |
Author: | MysticVegeta [ Tue Jul 19, 2005 4:30 pm ] | ||
Post subject: | |||
Here is a basic model i made of what you are talking about but i didnt put in the file writing/reading, you have to do that, cant entirely do it for you.
|
Author: | Cervantes [ Tue Jul 19, 2005 11:10 pm ] | ||
Post subject: | |||
Arrays work well with for loops, Mystic. [yoda voice]mMMmm, learn well, this you must[/yoda voice] Also, I don't think that feature of 'preventing the same letter from appearing more than once in a name' should exist. Just look at "William". Two i's, two l's.
I've got some pretty neat ones. "Nasaki" and "Rice" were my favourite. ![]() |
Author: | Lancelot [ Wed Jul 20, 2005 2:34 am ] | ||
Post subject: | |||
Thank you, people! ![]() I don't know why I wanted to use a file... Perhaps to have ability to delete letters that I don't like. ![]() Here are some edits:
Now it can display words with odd amount of letters, but the part that does it looks really ugly. Is there a better way to do it? And, does anyone has any ideas on how to make first letter capital? |
Author: | Cervantes [ Wed Jul 20, 2005 6:07 am ] | ||||
Post subject: | |||||
Lancelot wrote: And, does anyone has any ideas on how to make first letter capital?
You can download my Improved String Module, then use the Capitalize method, like this:
or maybe like this:
If you look at the code inside the module, you'll get an idea of how to do it. Basically, you work with ASCII values. If the first letter is lower case, subtract 32 to it's ASCII value. If any other letters are upper case, add 32 to their ASCII values. |
Author: | MysticVegeta [ Wed Jul 20, 2005 8:22 am ] | ||
Post subject: | |||
lol yoda voice. lol i forgot about "for" loops ![]() Anyways, Isnt there a "Str.Upper" command in turing 4.05?
|
Author: | Cervantes [ Wed Jul 20, 2005 3:38 pm ] | ||||
Post subject: | |||||
Yes, Str.Upper would work as well. Mind you, you then have to go to the trouble of this:
I hate having to work with strings like that. It sure would be nice if Turing would let us treat the string as an array of chars (and therefore allow us to change any element (or letter, in this case) of the array (or name, in this case)). Also, doing that would leave all the other letters as whatever case they were, which we probably don't want. To fix that, we'd have to do this:
That's essentially what the Capitalize method does. wtd wrote: Don't reinvent the wheel if there's an existing library function to do it for you ![]() |
Author: | Delos [ Wed Jul 20, 2005 6:44 pm ] |
Post subject: | |
Cervantes wrote: wtd wrote: Don't reinvent the wheel if there's an existing library function to do it for you I once did that unknowlingly with strint(). It was back in grade 10, and I was error trapping a programme of mine, so I figured out that if I were to make sure int-input was indeed int, I'd have to accept it as string, type-cast it and check it. Wow...such a long time ago. |
Author: | Lancelot [ Wed Jul 20, 2005 9:32 pm ] | ||
Post subject: | |||
Ok, thanks everyone, no more questions. Final version with file output feature.
|
Author: | Delos [ Wed Jul 20, 2005 10:36 pm ] | ||
Post subject: | |||
Not too bad. I particularly like the way you use the seek line to go to the end of the file. Now, here's some notes: - you don't need that delay, it's just annoying. - now that you've gotten the basic vowel-consanant-vowel thing going on, how about looking into binary trees? Basically, you select a node (let's say the letter 'r') then decide whether to add a vowel or a consonant. If you choose consonant, you bring up a list of possible consonants that can go after 'r', for example "b, d, k, t". You choose from within this. This becomes your next node, and you make the choice again. Letters like 'q' will only have one vowel choice, and letters like 'x' might be a little finicky to have a letter after them, so you will need to also designate an 'end of word' character. Sound like fun? I might just try it myself. [edit] Ok, I just finished it. It's really primitive. It would work much better if it ran based on syllabals instead of just letters. However, it works somewhat well. I've almost gotten some understandable words out of it! Note that the 'wordLen' thing doesn't quite work... ![]()
Here's the source file: [Edit 2] MOIST, SAD, PLOP, QUA, HYMN Yeah! Real words! w00t. |
Author: | Lancelot [ Thu Jul 21, 2005 12:25 am ] |
Post subject: | |
Wow... Impressive. A bit too hard for me yet, but i'll try to understand. Delay thingy - just so you could read the words as they appear, cause if you want like hundred of words then it goes over the screen. |
Author: | MysticVegeta [ Thu Jul 21, 2005 7:34 am ] |
Post subject: | |
well take your time and remember the Turing Walkthrough is your best friend. I learned records only a couple of days ago through the walkthrough. ![]() |