-1
我的计划的目的是让来自用户输入一个字符串,删除和计数所有的元音。此外,该程序将继续运行,直到他们点击“---”结束程序。但是,我卡住了,无法找到我的程序出了什么问题。例如:如果用户输入:“你怎么样?”,输出应该是:“HW RŸ?”。 对不起,我是一个菜鸟,这是我的第一个编程语言,我很缺乏经验吧。C++,删除和couting的所有元音在一个字符串
============================================== =======
#include<iostream>
#include<string>
using namespace std;
int main()
{
cout << "Please enter a sentence" << endl;
string sentence;
getline(cin,sentence);
while (true) {
getline(cin, sentence);
if (sentence = "---")
break;
int j, a, e, i, o, u;
for (j = 0; j < sentence.length(); j++)
{
if (sentence[j] == "a" || sentence == "A")
{
a++;
}
else if (sentence[j] == "e" || sentence == "E")
{
e++;
}
else if (sentence[j] == "i" || sentence == "I")
{
i++;
}
else if (sentence[j] == "o" || sentence == "O")
{
o++;
}
else if (sentence[j] == "u" || sentence == "U")
{
u++;
}
cout << sentence << "number of " << "a :" << a << "e :" << e << "i :" << i << "o :" << o << "u :" << u;
}
}
return 0;
}
应该是'如果(全文[J] == 'A' ||句子[J] == 'A')' –
我建议你打开所有的编译器警告。如果您在此处询问有关调试帮助,请逐字添加所有编译器错误消息。 –