Hey guys. I coded the following program below: but I have a problem... I think its perhaps the logic I have used is not too good... here it goes...
The program below should: ask the user to enter a letter ('a' to 'z' or 'A' to 'Z') and outputs VOWEL or CONSONANT depending upon the input. You should use a switch statement to identify the vowels and cascade these cases togther. If the user types in a character which is not a letter you should print out the message NOT-A-LETTER.
I get the program to do all of these but when I execute it and say I type in A the output I get is A is a Vowel and then A is a CONSONANT as well<< its this extra bit which is my problem... It shows that all the Vowels are vowels but are also Consonants which dose not make sense.
Here is the c code:
#include <stdio.h>
#include "simpleio.h"
int main() // This program has the BOTH feature added to it
{
char letter;
printf("Please enter a letter 'A'-'Z' or 'a'-'z' : \n");
letter = getchar();
if ((letter >= 'A' && letter <= 'Z' ) || (letter >='a' && letter <= 'z'))
{
printf(" %c is a CONSONANT\n", letter);
}
else
{
printf("NOT-A-LETTER\n");
}
switch(letter)
{
case 'A' : printf(" A is a vowel\n"); break;
case 'a' : printf(" a is a vowel\n"); break;
case 'E' : printf(" E is a vowel\n"); break;
case 'e' : printf(" e is a vowel\n"); break;
case 'I' : printf(" I is a vowel\n"); break;
case 'i' : printf(" i is a vowel\n"); break;
case 'O' : printf(" O is a vowel\n"); break;
case 'o' : printf(" o is a vowel\n"); break;
case 'U' : printf(" U is a vowel\n"); break;
case 'u' : printf(" u is a vowel\n"); break;
case 'Y' : printf(" Y is BOTH\n "); break;
case 'y' : printf(" y is BOTH\n "); break;
}
return 0;
}
many thanks hope you can help me out.