im making hangman.. and its not VS the cpu, its VS a human. So they way i have it set up is 1 player inputs a word, and the other enters letters. say i do..

:input "Your word please",Str1
:length(Str1)->L

now the calculator knows they entered a word and how long it is.. but how does it...

1) know what letters in what order were entered
2) know if the player guesses a correct letter

please help, i have trouble using Str's :(
You'll want to use the inString() function to check if each letter that the user enters is in their string. sub() can pick out substrings and individual letters. Can you be a bit more specific about what your program's design flow is so we can advise you how to use said string functions effectively in your program?
Ohh i gotcha, and sure. all my program does so far is starts at the home screen, asks the player for a word, then the calculator is handed to the second player.. by then the graph screen will show.."number of letters in word" and right below that shows the number of letters. that is as far as i got; which is where i got stuck with the letter guessing. would you like me to post my code?
joshie75 wrote:
Ohh i gotcha, and sure. all my program does so far is starts at the home screen, asks the player for a word, then the calculator is handed to the second player.. by then the graph screen will show.."number of letters in word" and right below that shows the number of letters. that is as far as i got; which is where i got stuck with the letter guessing. would you like me to post my code?
Yeah, I think that would be a good idea. It seems to me that you'll need at least three strings (or two strings and a list): the full word, the word as the player has guessed it so far, and the letters that have been guessed.
Code:


Code:
:Clrhome
:Clrdraw
:AxesOff
:Input "Your word please",Str1
:length(Str1)->L
:Text(1,1,"Number of letters"
:Text(10,1,L
:Pause
:Lbl 1
:Clrhome
:Input "pick one letter ",Str2


unfortunately that is all i have written so far. and i didnt even know if storing the letter as Str2 was right so i decided to wait and ask you.
I would recommend inputting a string, and then use that to make a list that would contain the answers, maybe a string for guesses, and an output list. IMHO, lists are far better suited for most of your needs here than strings, like checking if a single value equals any elements of the whole answer, and outputting that as a list.
so would i do...

:input "Your word please",L1

or something?
inString(Str1,Str2) will tell you the position of the first instance of Str2 in Str1, but what if Str1 has more than one E?

I see two ways of making this work effectively: You could use inString(Str1,Str2,N) to find the location of Str2 with the search beginning at N. With each one found, you would add one to N and then run the line again to find the next one, repeating until inString( returns zero.

Alternatively, if the string is generally small, you could use inString(Str1,Str2) once to decide whether to move onto the next phase, which would use For(P,1,length(Str1)) and If sub(Str1,P,1)=Str2. I'll end my thoughts there.

The home screen is great for experimenting with functions.
So you're using Str1 to store the word. I guess you'll want Str3 to contain length(Str1) dashes or minus signs, then since you're fetching guesses into Str2, using Str4 to store the set of letters already guessed?
were goose, thanks so much, you just cleared that up for me really well!! Smile
so with the "instring(" command... i just tried it and it returns a number with how many of the letters you picked were in the word.
now that i have the guessing part almost done..

what im dreaming of now is listing a-z on the graph screen. once a letter is picked, how can i tell the program to put a small line through the same letter picked? :S
sorry im really new to programing Sad
joshie75 wrote:
so would i do...

:input "Your word please",L1

or something?

Well, what you'd probably want to do is input a string, then convert the string to a list, like so:

Code:
:Input "WORD:",Str1
:length(Str1→dim(L1
:For(A,1,length(Str1
:inString("ABCDEFGHIJKLMNOPQRSTUVWXYZ",sub(Str1,A,1→L1(A
:End

This code will find out what character is used for each element in the string, then store a numerical value of that (A=1, B=2, etc.) and store that into it's corresponding element in L1. This code could be optimized even further, but I wanted to be sure you understood this.
joshie75 wrote:
so with the "instring(" command... i just tried it and it returns a number with how many of the letters you picked were in the word.
Hm, nope. Experiment more. Your conclusion is false.
hmm, it either comes back with 0,1, or 2. what does this mean? Razz
joshie75 wrote:
hmm, it either comes back with 0,1, or 2. what does this mean? :P
Keep playing around with inString(. Try and figure it out for yourself. You'll need to be able to figure things out without being told the answer eventually.
I will give a very small, but useful hint, pay attention to the output, and both strings, that is all I will say.
Oh weregoose, i see what you're saying now!
so maybe i could do something like this?

Code:
:N->1
:While Z>0
:instring(Str1,Str2,n)->Z
:N+1->N
:end
joshie75 wrote:
Oh weregoose, i see what you're saying now!
so maybe i could do something like this?

Code:
:N->1
:While Z>0
:instring(Str1,Str2,n)->Z
:N+1->N
:end


What exactly are you trying to do there?
well what i was going for is..
it would scan string1 to see if string2 was there, starting at 1 (N->1).
then once it completed that scan, it would start at that position and scan again and keep repeating until no more of the same letters were found.
i guess for that code i meant N+Z+1->N.. Right? wouldnt that make it start at the spot after where it just found that letter?
joshie75 wrote:
well what i was going for is..
it would scan string1 to see if string2 was there, starting at 1 (N->1).
then once it completed that scan, it would start at that position and scan again and keep repeating until no more of the same letters were found.
i guess for that code i meant N+Z+1->N.. Right? wouldnt that make it start at the spot after where it just found that letter?


You will want to start the next line 1 above where you just found the last spot, so try Z+1->N and tell me what you get.
Well now that i've entered those few lines into my calculator heres my program as of now.

Code:
:1->N
:ClrHome
:ClrDraw
:AxesOff
:Input "Your word please",Str1
:length(Str1)->L
:Text(1,1,"Number of letters"
:Text(10,1,L
:Pause
:Lbl 1
:ClrHome
:Input "pick one letter ",Str2
:While Z>0
:inString(Str1,Str2,N)->Z
:Z+1->N
:End

When i enter my word, i entered, "GOODBOY" lol yes i realize that is two words, i just used to for repetition of a letter; then it goes to the graph, i press enter to exit the pause, and then i enter the letter "O" as my guess and hit enter. It just says "Done".
hmm Razz
i guess it is because the fast the nothing is to be displayed;
how do i get it to display the number of letters found? Razz
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 4
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement