Member-only story
Calculate Scrabble Word Score in C++
Introduction
Scrabble is a popular word game in which players form words on a game board using letter tiles. Each tile has a specific point value, and the objective of the game is to accumulate the highest score. In this tutorial, we will learn how to write a program in C++ that calculates the score of a given Scrabble word.
Objective
The goal of this program is to take a word as input from the user, calculate its Scrabble score based on letter values, and output the total score. The program will use a predefined point system for the letters of the alphabet as follows:
- A, E, I, O, U, L, N, S, T, R: 1 point
- D, G: 2 points
- B, C, M, P: 3 points
- F, H, V, W, Y: 4 points
- K: 5 points
- J, X: 8 points
- Q, Z: 10 points
C++ Code
#include #include #include using namespace std; // Function to calculate Scrabble score int calculateScrabbleScore(const string& word) { // Point system for each letter unordered_map<char, int> letterPoints = { {'A', 1}, {'E', 1}, {'I', 1}, {'O', 1}, {'U', 1}, {'L', 1}, {'N', 1}, {'S', 1}, {'T', 1}, {'R', 1}, {'D', 2}, {'G', 2}, {'B', 3}, {'C', 3}, {'M', 3}, {'P', 3}…