#include <cs50.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
int calculate_points(string word);
int main(void)
{
// getting input
string word1 = get_string("Player1: ");
string word2 = get_string("Player2: ");
// calculating points
int points1 = calculate_points(word1);
int points2 = calculate_points(word2);
// comparing points and printing the result
if (points1 < points2)
{
printf("Player 2 wins!\n");
}
else if (points1 > points2)
{
printf("Player 1 wins!\n");
}
else
{
printf("Tie!\n");
}
}
int calculate_points(string word)
{
// declaring variables
const int n = 26;
int total = 0;
// declaring arrays
char characters[n] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int points[n] = {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};
// looping through each character in the word
for (int i = 0; i < strlen(word); i++)
{
// looping through each character in the array of characters and comparing to ones in the word
char current_char = tolower(word[i]);
for (int j = 0; j < n; j++)
{
// if comparsion is true, adding to a total value
if (current_char == characters[j])
{
total += points[j];
}
}
}
return total;
}