Scrabble Lab Solution

#include <ctype.h>
#include <cs50.h>
#include <stdio.h>
#include <string.h>

// Points assigned to each letter of the alphabet
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};
            //  A  B  C                                                                     Z
            //  0. 1. 2.                                                                    25

int compute_score(string word);

int main(void)
{
    // Prompt the user for two words
    string word1 = get_string("Word 1: ");
    string word2 = get_string("Word 2: ");

    // Compute the score of each word
    int score1 = compute_score(word1);
    int score2 = compute_score(word2);

    // Print the winner
    if (score1 > score2)
    {
        printf("score 1 is greater\n");
    }
    else if (score2 > score1)
    {
        printf("score 2 is greater\n");
    }
    else
    {
        printf("tie\n");
    }

}

int compute_score(string word)
{
    // Compute and return score for word

    // initialize a running sum
    int score = 0;

    // loop over strlen number of chars in my word
    for (int index = 0, n = strlen(word); index < n; index++)
    {
        // check if letter:
        if (isalpha(word[index]) != 0)
        {
            // convert each char to uppercase (we could choose either case) to make our checks easier
            // 'A' -> 65 -> represented in my POINTS arr at index 0 -> subtract 'A'
            // 'C' -> 67 -> index 2 -> subtract 'A'
            // 'Z' -> 90 -> index 25 -> subtract 'A'
            // add on the value at this index to a running sum
            int POINTSindex = toupper(word[index]) - 'A';
            score += POINTS[POINTSindex];
            // cats -> c -> C -> 67, subtract 65 -> 2 -> POINTS[2] -> 3 -> add on to score!
        }
        // else do nothing -> no need for else!
    }
    printf("score: %i\n", score);
    return score;
}