Computer Science Canada Question on Strings |
Author: | itsaLOSTBOY [ Sun Jan 24, 2016 1:44 am ] | ||
Post subject: | Question on Strings | ||
What is it you are trying to achieve? <Is it possible to make a large string without making one string variable for each letter of the alphabet?" For my program if the user clicks an incorrect key twice or more it should not create an image so I need to create a large string which would make sure if the user clicks it twice it would not draw the image it would usually draw. > What is the problem you are having? <When I try to create long string it says I did it wrong.> Describe what you have tried to solve this problem <I tried to make large string> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using <4.1.1> |
Author: | Insectoid [ Sun Jan 24, 2016 7:49 am ] |
Post subject: | RE:Question on Strings |
I honestly don't understand what you're asking. Take the time to properly explain what you're doing. Turing supports strings up to 255 characters though. I doubt you need a string longer than that. |
Author: | itsaLOSTBOY [ Sun Jan 24, 2016 3:39 pm ] |
Post subject: | Re: Question on Strings |
So for my hangman game it will draw a body part if you click the wrong letter but if you click the same wrong letter twice then it would draw two body parts so to fix it I would use a large string. So the string I showed above is it correct? |
Author: | Insectoid [ Sun Jan 24, 2016 5:42 pm ] |
Post subject: | RE:Question on Strings |
Why do you need a large string? I don't understand your logic. How are you making the leap from 'drawing a body part twice' to 'need a large string'? |
Author: | itsaLOSTBOY [ Sun Jan 24, 2016 5:52 pm ] |
Post subject: | Re: Question on Strings |
Well i was told to by my teacher and so I thought that it must be the only way so I came here for clarification |
Author: | Insectoid [ Sun Jan 24, 2016 5:56 pm ] |
Post subject: | RE:Question on Strings |
There is rarely just one way to do something in programming. Do you want to know how to make a large string, or do you want to know how to stop the user from entering the same letter twice? |
Author: | itsaLOSTBOY [ Sun Jan 24, 2016 5:58 pm ] |
Post subject: | Re: Question on Strings |
do you know how to do it with a large string? |
Author: | Insectoid [ Sun Jan 24, 2016 6:13 pm ] |
Post subject: | RE:Question on Strings |
Sure. That might not be the easiest or best method though. Why don't you forget about strings and try to do it your way. You will need to record what guesses the user has made, at least. |
Author: | itsaLOSTBOY [ Sun Jan 24, 2016 6:57 pm ] |
Post subject: | Re: Question on Strings |
im not sure on how to do it though |
Author: | Insectoid [ Sun Jan 24, 2016 7:34 pm ] |
Post subject: | RE:Question on Strings |
Have you tried anything yet? |
Author: | itsaLOSTBOY [ Sun Jan 24, 2016 7:50 pm ] |
Post subject: | Re: Question on Strings |
I was thinking of doing a lot of if statements for each letter of the alphabet like if key = a then Aalreadyprinted = 1 but idk what to do after and i think it would take too long to do |
Author: | Insectoid [ Sun Jan 24, 2016 7:54 pm ] | ||
Post subject: | RE:Question on Strings | ||
That would work, but it would take a while. Or instead of a whole bunch of variables, you could store all the guesses in one variable, like maybe a string? Something like this:
|
Author: | itsaLOSTBOY [ Sun Jan 24, 2016 10:27 pm ] |
Post subject: | Re: Question on Strings |
how would you do the if statement, specifically the decision portion? |
Author: | Insectoid [ Mon Jan 25, 2016 5:54 am ] |
Post subject: | RE:Question on Strings |
The index command might be useful here. |
Author: | itsaLOSTBOY [ Mon Jan 25, 2016 4:05 pm ] |
Post subject: | Re: Question on Strings |
Is this how you use index and do it? var alreadyguessed : string := 'H' + 'U' + 'L' + 'K' var guess: char if index (alreadyguessed) = guess then |
Author: | Insectoid [ Mon Jan 25, 2016 6:48 pm ] |
Post subject: | RE:Question on Strings |
Have you read the documentation on index? The documentation for Turing is available here. |