0

Right where it says " <= 'Z' " the complier puts a ^ to the < sign and says error: expected expression. I included . I have no idea what is wrong with this statement!

int hash_func (char* key)
{
int output = toupper(key[0]) - 'A';
if (toupper(key[1] >= 'M' && <= 'Z'))
{
    output += 26;
}
return output % SIZE;

}

1

First of all your parentheses are possibly wrong placed. From what I get, you want to find if the upper case of key[1] is within 'M' and 'Z'. You should keep in mind that a programing language is more strict than a natural language. So even if in English you can say "if n is larger than 0 and smaller than 2", in programming you have to say "if n is larger than 0 and n is smaller than 2".

So what you should have instead is:

if ((toupper(key[1]) >= 'M') && (toupper(key[1]) <= 'Z'))

You can also use

char c = toupper(key[1]);

so that you don't calculate the upper of key[1] two times.

2
  • 1
    I think you have answered like every single one of my questions. You should be getting paid for this ;) – Fijj Sep 16 '15 at 18:48
  • 1
    Hahaha. That's what I aim for. To be paid to write programs one day. :) Keep coding and you will be where I am now in no time! – ChrisG Sep 16 '15 at 19:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .