Write a value-returning function, isVowel, that returns the value true if a give
ID: 3607648 • Letter: W
Question
Write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false. ***Collect the user's input in the main() and pass it to the isVowel() function. ***Use Call-by-Reference (value returning function). ***Validate the user's input (allow only alphabet characters: a through z, or A through Z). ***Allow the user to repeat the program. ***Match the output below (OUTPUTS section). OUTPUTS: ************************************************************************************** Enter a character between a and z (or A and Z): a a is a vowel: 1 Do you want to repeat this program? y/n > y ********************************** Enter a character between a and z (or A and Z): E E is a vowel: 1 Do you want to repeat this program? y/n > y ********************************** Enter a character between a and z (or A and Z): B B is a vowel: 0 Do you want to repeat this program? y/n > y ********************************** Enter a character between a and z (or A and Z): @ Invalid input. Please Enter a character between a and z (or A and Z). Enter a character between a and z (or A and Z): b b is a vowel: 0 Do you want to repeat this program? y/n > y ********************************** Enter a character between a and z (or A and Z): 9 Invalid input. Please Enter a character between a and z (or A and Z). Enter a character between a and z (or A and Z): c c is a vowel: 0 Do you want to repeat this program? y/n > n **********************************
Explanation / Answer
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
int checkForVowel(char c);
int main()
{
int result=0;
while(true)
{
char c,choice;
printf(" Enter a character:");
scanf("%s",&c);
result=checkForVowel(c);
printf(" Character is vowel:%d",result);
printf(" Do you want to continue? y/n:");
scanf("%s",&choice);
switch(choice)
{
case 'y':
case 'Y':
break;
case 'n':
case 'N':
printf(" You entered No, exiting the program");
exit(0);
default:
printf(" Please enter a valid character");
break;
}
}
clrscr();
}
int checkForVowel(char c)
{
if(c=='a'||c=='A'||c=='e'||c=='E'||c=='i'||c=='I'||c=='o'||c=='O'||c=='u'||c=='U')
return 1;
else
{
if(c>64 && c<123)
if(c>90 &&c<98)
printf("Please dont enter any other value than character.");
return 0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.