Wednesday, 18 September 2013

Programming in C, Switch Case problems

Programming in C, Switch Case problems

#include <stdio.h>
int main(void)
{
char ch;
//character = ch
printf("Please type a character [A-Z or a-z] ('x'to exit):");
scanf("%c", &ch);
switch(ch) //switch statement
{
case 'a':
printf("%c is a vowel.\n", ch);
break;
case 'e':
printf("%c is a vowel.\n", ch);
break;
case 'i':
printf("%c is a vowel.\n", ch);
break;
case 'o':
printf("%c is a vowel.\n", ch);
break;
case 'u':
printf("%c is a vowel.\n", ch);
break;
case 'A':
printf("%c is a vowel.\n", ch);
break;
case 'E':
printf("%c is a vowel.\n", ch);
break;
case 'I':
printf("%c is a vowel.\n", ch);
break;
case 'O':
printf("%c is a vowel.\n", ch);
break;
case 'U':
printf("%c is a vowel.\n", ch);
break;
default:
if(ch != 'x'){
printf("%c is a consonant.\n", ch);
break; }
else if(ch == 'x'){
printf("%c is a consonant.\n", ch);
break; }
}
I have been having much trouble with this code. I have it perfect however
it needs to keep repeating until 'x' is entered. Tried a while loop,
couldn't have any luck, just recently tried the if statement in the
default, that doesnt work either. I'm so close if anyone could give me a
little insight!

No comments:

Post a Comment