Answer to Question #346034 in C for Chariz

Question #346034

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.


Input



1. A series of characters



Output



Multiple lines containing message prompts for characters.



Enter·a·character:·c


c



Enter·a·character:·f


f



Enter·a·character:·a


a

1
Expert's answer
2022-05-30T15:14:41-0400
#include <stdio.h>
#include <stdbool.h> // not necessary but "bool isVowel" looks better
int main()
{
    int i = 0;
    char letter;
    bool isVowel;
    do{
        printf("Enter a character: ");
        scanf(" %c", &letter);
        printf("%c \n", letter);


        switch(letter){
            case 'a': case 'e': case 'i': case 'o': case 'u': case 'y':
                isVowel = true;
                break;
            default:
                isVowel = false;
        }
        i++;
    } while(i<5&&!isVowel);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS