This program is supposed to count the number of letters, punctuations and numbers a user enters.
The problem I'm having is that "letter" is showing as 2 when I only type in 1 letter. If I assign letter to -1, then it all works fine. So what is wrong here?
Code:
#include <stdio.h>
#include <conio.h>
int main(void)
{
char ch;
int digit, punc, letter;
printf("Enter number, punctuation or letter: \n");
digit = 0;
punc = 0;
letter = 0;
do {
ch = getche();
switch(ch) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
digit++;
break;
case '.':
case ',':
case '?':
case '!':
case ':':
case ';':
punc++;
break;
default:
letter++;
}
} while(ch!='\r');
printf("\nDigits: %d\n", digit);
printf("Punctuation: %d\n", punc);
printf("Letters: %d\n", letter);
getche();
}