2. A, e, i, o, u?
by CodeChum Admin
We've had enough about numbers, so why don’t we try evaluating characters now?
If you know how to identify what the vowel letters are, and you know how to count up to 5, then you’re good to go!
Instructions:
Using a do…while() loop, continuously scan for characters (one per line) and print it out afterwards. Remember to place a space before the character's placeholder when scanning so that the newline characters will be ignored and the correct values will be scanned.
The loop shall terminate due to either of the following reasons:
The inputted character is a vowel
The number of inputted characters has already reached 5.
For all of the test cases, it is guaranteed that if the number of inputted characters is less than 5, then there must be a vowel from among the inputted characters. Also, it is guaranteed that all the characters are in lowercase.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(){
char letter;
int count=0;
do{
scanf("%c", &letter);
printf("%c",letter);
char c = tolower(letter);
if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
break;
}
count++;
} while(count<5);
getchar();
getchar();
return 0;
}
Comments
Leave a comment