我正在制作一个基本程序来计算字符串的元音。现在,我想尝试使用布尔函数,因为我感觉很喜欢,但是每当我用元音输入字符串时,它都不会增加vowel
的整数。
其中有一个错误,但我找不到它。
#include <iostream>
using namespace std;
bool isVowel(char){
char chara;
return (chara == 'A' || chara == 'E' ||
chara == 'I' || chara == 'O' || chara == 'U' || chara == 'Y' || chara == 'a' || chara == 'e' || chara == 'i' || chara == 'o' || chara == 'u' || chara == 'y');
}
int main()
{
string input;
int vowels = 0;
cout << "Vowel checker v1.0.0\n";
cout << "Type the word that you want to count the vowels of.\n";
cin >> input;
for(unsigned int i = 0; i<input.length(); i++){
if(isVowel(input.at(i)) == true){
vowels++;
}
}
cout << "Including a, e, i, o, u, and y, that word contains " << vowels << " vowels.\n";
}
答案 0 :(得分:0)
您弄错了函数参数的语法,并无意间写了一些合法的东西,但是没有按照您的预期去做。像这样写
bool isVowel(char chara) {
return chara == 'A' || chara == 'E' ||
chara == 'I' || chara == 'O' || chara == 'U' || chara == 'Y' ||
chara == 'a' || chara == 'e' || chara == 'i' || chara == 'o' ||
chara == 'u' || chara == 'y';
}