how to eleminate F1 F2

when i input F1 the getch() still get it eventhough my code has elemenated F1 and stuff like that already ! can you help me to figure out

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream>
#include<cstring>
#include<conio.h>

using namespace std;
int main(){
int a;

cout<<"PASSWORD= ";

while(a!=13)
{
	a=getch();
	if(a!=0+59&&a!=0+60&&a!=0+61&&a!=0+62&&a!=0+63&&a!=0+64&&a!=0+65&&a!=0+66&&a!=0+67&&a!=0+68){cout<<"#";}
	
}
}
Last edited on
i know how to do it...what i mean is why my code is wrong ? can you show me
If you want to exclude a range of characters, you might put them in a string and test to see if the character is found in that string.

This long and obfuscated line:
 
if(a!=8&&a!=0+59&&a!=0+60&&a!=0+61&&a!=0+62&&a!=0+63&&a!=0+64&&a!=0+65&&a!=0+66&&a!=0+67&&a!=0+68){cout<<"#";}


could more legibly be written like this:
1
2
3
4
    if ( !strchr("\b;<=>?@ABCD", a) )
    {
        cout << "#";
    }

See reference:
http://www.cplusplus.com/reference/cstring/strchr/

Also note: in the original code, int a; is not initialised - it could have any value at all, meaning the loop might not even execute. Give it some sort of value, (so long as it isn't 13)
 
    int a = 0;

Last edited on
you still dont understand me....
a!=0+59
is F1...because it was eleminated ....so when i hit F1 button from keyboard the symbol
#
should not be printed....
but in fact...when i hit F1 button the screen still show me
#

so can you fix on my code plsz
I do understand, you want to eliminate the function keys - and I already showed you in the other thread a possible way to at least start off. You might want to build on that if you need something with additional capabilities.

What I don't understand is why you instead set off in another direction with this:
 
a!=0+59


Do you realise that 0 + 59 gives 59? And do you also understand that the characters are represented internally as numeric values, so that character 59 (in the ASCII table) is the semicolon symbol ';'. So
 
a!=0+59
is effectively the same as
 
a != ';'


Take a look at the ASCII table and see which characters are represented by the numbers 59 to 68 which you are trying to use.

http://www.theasciicode.com.ar/ascii-printable-characters/semicolon-ascii-code-59.html
Last edited on
crystal clear...that's the answer that i have been watting for a long long time...a!=0+59 is just the same as a!=';'...thanks for your help...i really realy apreciate that :)
Last edited on
Topic archived. No new replies allowed.