Member-only story
Calculate Scrabble Word Score in C Programming
Introduction
Scrabble is a popular word game that involves forming words on a board using lettered tiles. Each tile has a point value, and the goal is to create words that accumulate the highest score. In this guide, we’ll learn how to calculate the score of a Scrabble word using the C programming language.
Objective
The objective of this program is to calculate the score of a given Scrabble word based on the individual letter values. Each letter in the Scrabble game has a different point value. The program will take a word as input, and it will return the total score based on the points assigned to each letter in that word.
Program Code
#include #include // Function to calculate the Scrabble score of a word int calculateScrabbleScore(char word[]) { int score = 0; int i = 0; char letter; // Define the point values for each letter int letterPoints[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 3, 2, 4, 1, 4, 1, 8, 4, 10, 1, 1, 3, 10}; // Iterate through each letter in the word while ((letter = word[i++]) != '\0') { // Convert to uppercase to handle case-insensitivity letter = toupper(letter); // Check if the letter is a valid letter if (letter >= 'A' && letter <= 'Z') { // Calculate the score for the letter score += letterPoints[letter - 'A']; }…