im trying to count the letters in the words from 1 (one = 3) to 1000 ( one = 3 + thousand = 8 giving a total of 11)

apparently the answer is 21124 and i get 21584 460 more.Code:#include <stdio.h> #include <stdlib.h> #define HUNDRED_AND 10 #define HUNDREDS 7 #define THOUSAND 11 #define LIMIT 1000 int units(int units); int tens(int tens); int ten_to_nineteen(int units); int count_letters(int number); int main() { int i; long long unsigned int letter_count = 0; for (i = 1; i < LIMIT; i++) { letter_count += count_letters(i); } letter_count += THOUSAND; //and the letters for 1000 onto the total printf("number of letters in all the numbers between 1 and 1000 inclusive are %llu", letter_count); return 0; } int units(int units) { int result; switch (units) { case 1: result = 3; //3 letters in the word one. break; case 2: result = 3; break; case 3: result = 5; break; case 4: result = 4; break; case 5: result = 4; break; case 6: result = 3; break; case 7: result = 5; break; case 8: result = 5; break; case 9: result = 4; } return result; } int tens(int tens) { int result; switch (tens) // deals with multiples of 10 { case 2: result = 6; //6 letters in the word twenty break; case 3: result = 6; break; case 4: result = 5; break; case 5: result = 5; break; case 6: result = 6; break; case 7: result = 7; break; case 8: result = 6; break; case 9: result = 6; } return result; } int ten_to_nineteen(int units) { int result; switch (units) { case 0: result = 3; //ten break; case 1: result = 6; //3 letters in the word eleven break; case 2: result = 6;//twelve break; case 3: result = 8;//thirteen break; case 4: result = 8;//fourteen break; case 5: result = 7; //fifteen break; case 6: result = 7; //sixteen break; case 7: result = 9;//seventeen break; case 8: result = 8;//eighteen break; case 9: result = 8;//nineteen } return result; } int count_letters(int number) { int unit, ten, hundred, total_letters_in_num = 0; unit = number % 10; ten = number % 100; ten /= 10; hundred = number / 100; if (unit > 0) { total_letters_in_num = units(unit); //count the number of letters in the number of units. } if (ten > 0) { if (ten == 1) { total_letters_in_num += ten_to_nineteen(unit); } else { total_letters_in_num += tens((ten));//count the number of letters in the number of groups of 10 } } if (hundred > 0) { total_letters_in_num += units(hundred); if (unit == 0 && ten == 0) //dealing with 100 200, 300 etc { total_letters_in_num += HUNDREDS; } else { total_letters_in_num += HUNDRED_AND; } } return total_letters_in_num; }

if have tried altering the loop to check my functions and each time by my reckoning i get the right answer. ie i counted up to 9 and got 36. tried counting in 10's from 10 to 90 and got the right answer same with counting in hundreds and counting in hundreds with i = 101.

so i cant see why its not working

coop