|
Well, you can use, as an earlier poster suggested, the "isalpha" function. Also there is an "isdigit" function. Finally there is a "tolower" function. All three are in the "cctype" library. I would have your lettercount array be an array of 26 integers rather than 100 since there are 26 letters in the alphabet. It looks like you are already using "isdigit" and have the "digit" section under control. For the letter tally section, assuming that the user entry is in a character array called "string" as you have it (I would change the name to something else to avoid confusion with the string class), you can do this (assuming lettercount is initialized to all zeroes already, as it is):
1. Go through "string" character by character starting with character 0.. 2. Using "isalpha" function, check if it is a letter. 3 If it isn't, go to step 7. 4. Using "tolower" function, convert letter to lower case. 5. Subtract 97 (which is the ASCII offset of 'a') from the resulting character to get the appropriate index of lettercount. 6. Increment lettercount for the index from step 5. 7. Go to next character in "string". 8. If more letters are left, go to step 2.
You'll end up with lettercount[0] containing the number of a's, lettercount[1] containing the number of b's, lkettercount[2] containing the number of c's, etc.
|