#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <math.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 };
char ALPHABET[] = { 'a' , 'b', 'c', 'd', 'e', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
int main(void) {
string word1 = "dog";
int score;
int tile;
int points;
int index;
int finish = strlen(word1);
for (tile = 0, index = 0, score = 0; tile == finish; index++) {
if (word1[tile] == ALPHABET[index]) {
points = index;
score = score + POINTS[points];
tile++;
index = -1;
}
}
printf("%i\n", score);
}
This program prints a value of 0
instead of what I think should be 5
based on letter scores? Please give me some insight as to how I can accomplish this. Should I not be using an if
statement inside a for
loop?