Instructions
Given code
#include <iostream>
using namespace std;
int main(void) {
char word[100];
cout << "Enter the word: ";
cin >> word;
int result = hasVowel(word);
if(result == 1) {
cout << "There is a vowel in the word \"" << word << "\"";
} else if(result == 0) {
cout << "There is no vowel in the word \"" << word << "\"";
}
return 0;
}
Ex
Enter·the·word:·CodeChum
There·is·a·vowel·in·the·word·"CodeChum"
#include <iostream>
#include <cstring>
using namespace std;
int hasVowel(char* word);
int main(void) {
char word[100];
cout << "Enter the word: ";
cin >> word;
int result = hasVowel(word);
if(result == 1) {
cout << "There is a vowel in the word \"" << word << "\"";
} else if(result == 0) {
cout << "There is no vowel in the word \"" << word << "\"";
}
return 0;
}
int hasVowel(char* word){
int v = 0;
char vowels[6] = {'a','o','e','u','i','y'};
for(size_t i=0; i<strlen(word); i++){
for(int j=0; j<6; j++){
if(tolower(word[i]) == vowels[j]){
v = 1;
}
}
};
return v;
}
Comments
Leave a comment