L.system

please i need help with my code below, when ever i enter a wrond password first it gives me an error which its suppose to, but when entering the correct code next it still gives me an error message. could someone help me counter this problem. cheers

Last edited on
Because you don't reset the value of 'Password'.
Try inserting Password.clear(); before line 32
Last edited on
@bazzy, i dont know how too thank you. am very grateful. but please could you help me come through with the password entry, cause for instance if i tpye in the password, i cant erase a character cause the backspace keeps reading as a character...
check if 'encrypt' is a backspace and if it is, remove the last character from the string and from the output, if not add it to the string and display an *

1
2
3
4
5
6
7
8
9
10
if (encrypt=='\b')
{
    Password.erase(Password.size()-1,1);
    cout << "\b \b";
}
else
{
    Password.push_back(encrypt);
    cout << '*';
}
thanks very much, but it still has a problem the ackspace deletes a character, but cant delete a second and the program freezes. is there anything that can be done to resolve this? i really appreciate your responses. thank you so much
What is the code you have now?
i have edited the earlier code i pasted above...
Move the line getting the next character outside the else block:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
while(encrypt != 13)
{
    if (encrypt=='\b')
    {
        Password.erase(Password.size()-1,1);
        cout << "\b \b";
    }
    else
    {
        Password.push_back(encrypt);
        cout << '*';
    }
    encrypt = _getch();  
}
i wanna thank you so much, you are the best its works... just being curious if i was gonna do the same thing for the 'tab' key who do i go about it..

i was also wondering if i could be helped with an array, so i could have more than one login username and password.. would you be kind enough to put me through...cheers
if you want to process in different ways many characters you should think of using a switch instead of if else . Anyway, try something like this if you need to act in only 3 ways
1
2
3
4
5
6
if (encrypt=='\b')//backspace
   //...
else if ( encrypt=='\t')// '\t' = tab
   //...
else//all others
   //... 


I suggest you a vector instead of an array, so it can increase its size.
You may want to be able to read names-password from a file

When entered a name or password you can see if it exists in a vector (or in an array) using STL count algorithm.

My final suggestion is using a class for the username and password
eg:
1
2
3
4
struct user
{
    string name, password;
};




http://www.cplusplus.com/reference/stl/vector/
http://www.cplusplus.com/reference/algorithm/count/
Last edited on
wanna thank you so much for your help and support, but the code for the tab, its really not working dont know if am putting it at the wrong place... could please point me in the right direction. you really are a helper. cheers
How do you want your program react to the tab?
in inputting a password, i think normally it doesnt do anything, so i'll take that option. but if you have a better option please be free to advice... thanks for all your replies, you the best ....cheers
so try:
1
2
3
4
5
6
7
8
9
10
11
12
if (encrypt=='\b')
{
    Password.erase(Password.size()-1,1);
    cout << "\b \b";
}
else if ( encrypt=='\t'); // semicolon = do nothing
else
{
    Password.push_back(encrypt);
    cout << '*';
}
Topic archived. No new replies allowed.