
-----------------------------------
ans4
Sat Oct 28, 2006 11:41 am

Password
-----------------------------------
I'm trying to write a program so that when you type something it shows up as asterisks like for a password and it tells you if you have it right or wrong. What I have so far works but only if you get it right on the first try. I think the problem has to do with the "word:= word + pass" but I can't figure it out.

var password := "123"
var pass : string (1)
var word : string := ""

loop
    locate (1, 1)
    put "Password " ..
    locate (1, 10)
    loop
        getch (pass)
        exit when pass = KEY_ENTER
        word := word + pass
        put "*" ..
    end loop
    if word = password then
        cls
        put "Hello"
        exit
    else
        locate (1, 30)
        put "Wrong password"
    end if
end loop

-----------------------------------
Ultrahex
Sat Oct 28, 2006 11:58 am


-----------------------------------
The Last Else you need to reset the password string


...


    if word = password then
        cls
        put "Hello"
        exit
    else
        cls
        locate (1, 30)
        put "Wrong password"
        word := ""
    end if


-----------------------------------
richcash
Sat Oct 28, 2006 11:59 am


-----------------------------------
Yes, it does have to do with word := word + pass. If the user enters 12, it's wrong, but the 12 stays there, so when the enter 123, it's still wrong because now it's 12123! You need to reset word to "" when it's the wrong password.
var password := "123"
var pass : string (1)
var word : string := ""

loop
    locate (1, 1)
    put "Password " ..
    locate (1, 10)
    loop
        getch (pass)
        exit when pass = KEY_ENTER
        word := word + pass
        put "*" ..
    end loop
    if word = password then
        cls
        put "Hello"
        exit
    else
        locate (1, 30)
        put "Wrong password"
        word := ""  %