Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Question on Strings
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
itsaLOSTBOY




PostPosted: 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



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:


<var WRONGLETTERS : string := "a" + "b" + "c" + "d">



Please specify what version of Turing you are using
<4.1.1>
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: 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.
itsaLOSTBOY




PostPosted: 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?
Insectoid




PostPosted: 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'?
itsaLOSTBOY




PostPosted: 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
Insectoid




PostPosted: 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?
itsaLOSTBOY




PostPosted: Sun Jan 24, 2016 5:58 pm   Post subject: Re: Question on Strings

do you know how to do it with a large string?
Insectoid




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
itsaLOSTBOY




PostPosted: Sun Jan 24, 2016 6:57 pm   Post subject: Re: Question on Strings

im not sure on how to do it though
Insectoid




PostPosted: Sun Jan 24, 2016 7:34 pm   Post subject: RE:Question on Strings

Have you tried anything yet?
itsaLOSTBOY




PostPosted: 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
Insectoid




PostPosted: 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:
code:
var alreadyGuessed : string
var guess : char

if (guess is in alreadyGuessed) then
    %letter was already guessed!
else
    alreadyGuessed := alreadyGuessed + guess %add guess to the string
    %draw body part
end if
itsaLOSTBOY




PostPosted: Sun Jan 24, 2016 10:27 pm   Post subject: Re: Question on Strings

how would you do the if statement, specifically the decision portion?
Insectoid




PostPosted: Mon Jan 25, 2016 5:54 am   Post subject: RE:Question on Strings

The index command might be useful here.
itsaLOSTBOY




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: