commit 8428b615c88a55b04d4fd4d261149894f560a1f4 Author: bot50 Date: Fri Feb 23 20:51:00 2024 +0000 kukemuna-cs50/problems/2024/x/scrabble@20240223T205100.033742776Z diff --git a/scrabble.c b/scrabble.c new file mode 100644 index 0000000..390dec7 --- /dev/null +++ b/scrabble.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +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 get_score(string word); + +int main(void) +{ + // Prompt user(s) for two words + string word_1 = get_string("Player 1: "); + string word_2 = get_string("Player 2: "); + + // Compute the score of each word + int score_1 = get_score(word_1); + int score_2 = get_score(word_2); + + // Print the winner + if (score_1 > score_2) + { + printf("Player 1 wins!\n"); + } + else if (score_1 < score_2) + { + printf("Player 2 wins!\n"); + } + else + { + printf("Tie!\n"); + } +} + +int get_score(string word) +{ + int score = 0; + int length = strlen(word); + + for (int i = 0; i < length; i++) + { + if (isalpha(word[i])) + { + word[i] = toupper(word[i]) - 65; + } + score += POINTS[(int) word[i]]; + } + return score; +}