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

Username:   Password: 
 RegisterRegister   
 Character Entering and checking
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Blade




PostPosted: Wed Apr 16, 2003 12:02 pm   Post subject: Character Entering and checking

is there any way that i could enter a character, check to see if its a word, then check to see if tis been entered again...
like i have a word - Cat... have the user enter a letter and check to see if the letter is in the word, but also check to see if he's entered that same letter before..

I'm not asking you to do this for me... i would just like to have some help with it.. i've been sittin here in this damned boring class days tryin to figure out a way.. but i think i'm having a week long brain fart
Sponsor
Sponsor
Sponsor
sponsor
Delta




PostPosted: Wed Apr 16, 2003 1:46 pm   Post subject: This is what I got

I'm confused but this is what I got out of it
code:

var word : string := ""
var ch : string(1)
var count : int := 0
var last : string := ""
loop
    put "Enter a word"
    get word
    put "Enter a character"
    getch(ch)
    last := last + ch
    for i : 1 .. last
        if ch = last(i) then
            put "The character has been used before"
        end if
    end for
    for i : 1 .. length(word)
        if ch = word(i) then
            count := count + 1
        end if
    end for
    put "The character is in the word ", count, " times"
end loop


Don't copy just use as a template
Blade




PostPosted: Wed Apr 16, 2003 2:13 pm   Post subject: (No subject)

that isnt really it.... but its along that idea... what i meant was..
-enter a word
-enter a letter
-if the letter is in the word, but hasn't been guess before, you get a point
-if the letter is in the word, but has been guessed, no points

sorry my question wasnt very clear.. i try to, hopefully this one clears it up
Catalyst




PostPosted: Wed Apr 16, 2003 2:17 pm   Post subject: (No subject)

index should be able to help will tell u if its in the word
Blade




PostPosted: Wed Apr 16, 2003 2:20 pm   Post subject: (No subject)

yeah... i can check to see if its in the word, but i cant figure out to index the already guessed letters, and check to see if its been used before... it has to be in the same if statement... doesnt it?
Catalyst




PostPosted: Wed Apr 16, 2003 2:36 pm   Post subject: (No subject)

it would be like this...


code:


var text : string
var ch : string (1) := ""
var guesses : string := ""
put "Enter text:"
get text
loop
    getch (ch)

    if index (guesses, ch) = 0 then
        guesses += ch
        if index (text, ch) not= 0 then
            put "It is in the word"
        else
            put "It is not in the word"
        end if
    else
        put "You have guessed that already"
    end if
end loop


youll have to use captalization functions to normalize it but that is pretty much it
Blade




PostPosted: Wed Apr 16, 2003 2:39 pm   Post subject: (No subject)

awwww i feel so stupid now Laughing ... thanks a lot catalyst... Smile
Blade




PostPosted: Thu Apr 17, 2003 4:14 pm   Post subject: (No subject)

also... i was playin around and i remembered that it was case sensitive... any way i can take this off? or get around it?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Apr 17, 2003 4:26 pm   Post subject: (No subject)

i belive someone already posted a function for converting cases around.

you add some number to the ASCII value (i dont remember which one)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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 1  [ 9 Posts ]
Jump to:   


Style:  
Search: