39 lines
1.4 KiB
C
39 lines
1.4 KiB
C
/*
|
|
Nicholas Pease
|
|
HW5C - User Input / Vowels
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#define NUMBER_OF_VOWELS 10
|
|
|
|
int main() {
|
|
// char input will hold input on each iteration. initialized to 0 for looping
|
|
// vowels contains all the vowels to check against
|
|
char input = '0';
|
|
char vowels[NUMBER_OF_VOWELS] = {'A','E','I','O','U','a','e','i','o','u'};
|
|
while (input != '#') {
|
|
printf("Enter a letter: ");
|
|
// using over getchar to protect against newline
|
|
scanf(" %c",&input);
|
|
// end of input, now on to calculation/display
|
|
if ((input >= 'A' && input <= 'Z')||(input>='a' && input<='z')) {
|
|
// is a letter in the english alphabet (Y IS NOT INCLUDED AS IT IS SOMETIMES A VOWEL)
|
|
int isVowel = 0;
|
|
int i = 0;
|
|
// check each vowel in vowels and compare against input
|
|
while (isVowel == 0 && i < NUMBER_OF_VOWELS) {
|
|
if (vowels[i] == input) isVowel = 1;
|
|
i++;
|
|
}
|
|
// since we know its a valid char, and if it isnt a vowel, make it a consonant
|
|
printf("\'%c\' is a %s\n",input,isVowel? "vowel":"consonant");
|
|
} else if (input == '#') {
|
|
printf("Good bye!\n");
|
|
} else {
|
|
// not a letter in the english alphabet
|
|
printf("\'%c\' is not a valid character\n",input);
|
|
}
|
|
}
|
|
return 0;
|
|
} |