
/* 
(c) 1995 by Dan Goldwater.  12/16/95
computes word value for a word puzzle contest
*/

#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>


// this defines the value of each letter
enum {NUL = 0, H, D, M, S, C, A, Q, F, V, Z, K, B, I, U, W, T, Y, G, P, L, O, E, J, R, N, X};

// lookup array for letter values
int letter_val[26] = {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 main(void)
{
  char in_word[40];         // the input word
  char *the_word;	// the input word
  int length;		// length of the_word
  int word_val;		// value of word
  int i;				// temp

  printf("\nEnter the word: ");
  scanf("%s", in_word);
  printf("\nYou entered: %s\n", in_word);

  the_word = _strlwr(_strdup(in_word));		// convert all letters to lower case
  length = strlen(the_word);

  word_val = 0;
  for(i=0; i<length; i++)
  {
	word_val += letter_val[the_word[i] - 97];  // 97 is the ascii value of "a"
  }

  printf("The value of this word is: %u\n", word_val);

  return 0;
}
