[ad_1]
I can’t figure out why my code doesn’t work for three inputs. We are supposed to create a scrabble game that compares two inputs(word1 and word2) based on the array POINTS. I also tried using the -65 approach for the upper case letters as well as changing the if/else statements but nothing is working for me.
#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};
int score = 0 ;
int compute_score(string word);
int main(void)
{
// Get input words from both players
string word1 = get_string("Player 1: ");
string word2 = get_string("Player 2: ");
// Score both words
int score1 = compute_score(word1);
int score2 = compute_score(word2);
if (score1 > score2)
{
printf("Player 1 wins!");
}
if (score1 < score2)
{
printf("Player 2 wins!");
}
if (score1 = score2)
{
printf("Tie!");
}
// TODO: Print the winner
}
int compute_score(string word)
{
for(int i=0; i<strlen(word); i++)
{
if islower(word[i])
{
score = score + POINTS[word[i]-97];
}
else if isupper(word[i])
{
word[i] = tolower(word[i]);
score = score + POINTS[word[i]-97];
}
else
{
score = score + 0;
}
}
return score;
// TODO: Compute and return score for string
}
Here are my outputs :
:) scrabble.c exists
:) scrabble.c compiles
:) handles letter cases correctly
:) handles punctuation correctly
:) correctly identifies 'Question?' and 'Question!' as a tie
:) correctly identifies 'drawing' and 'illustration' as a tie
:) correctly identifies 'hai!' as winner over 'Oh,'
:( correctly identifies 'COMPUTER' as winner over 'science'
expected "Player 1 wins!...", not "Player 2 wins!..."
:( correctly identifies 'Scrabble' as winner over 'wiNNeR'
expected "Player 1 wins!...", not "Player 2 wins!..."
:( correctly identifies 'pig' as winner over 'dog'
expected "Player 1 wins!...", not "Player 2 wins!..."
:) correctly identifies 'Skating!' as winner over 'figure?'
[ad_2]