Try this. I took
n
out and changed the line containing
wordScore+=
.
EDIT: But forgot to bring
word[i]
into the range 0..25 instead of 'A'..'Z'. :)
int POINTS[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3,
1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10};
int calc_score(const char* word)
{
for(int i = 0; i < strlen(word); i++)
{
if(word[i] >= 'a' && word[i] <= 'z')
{
word[i] = toupper(word[i]);
}
}
int wordScore = 0;
for(int i = 0; i < strlen(word); i++)
{
if(word[i] >= 'A' && word[i] <= 'Z')
{
wordScore += POINTS[word[i] - 'A'];
}
}
return wordScore;
}