课后作业统计元音字母的问题
#include <stdio.h>int main()
{
char ch;
int count = 0;
int a = 0, e = 0, i = 0, o = 0, u = 0;
printf("Please input your sentence:");
while((ch = getchar()) != '\n')
{
if(ch = 'a')
{
a++;
count++;
}
else if(ch = 'e')
{
e++;
count++;
}
else if(ch = 'i')
{
i++;
count++;
}
else if(ch = 'o')
{
o++;
count++;
}
else if(ch = 'u')
{
u++;
count++;
}
else
continue;
}
printf("There are %d vowels in this sentence\n", count);
printf("a(%d),e(%d),i(%d),o(%d),u(%d)\n",a,e,i,o,u);
return 0;
}
程序里面没用答案的switch。。。 目标是统计小写元音字母,但是统计结果是所有输入的字符,请大神帮忙看看是什么问题。。 你好在if() 里面的比较中用==而不是=
#include <stdio.h>
int main()
{
char ch;
int count = 0;
int a = 0, e = 0, i = 0, o = 0, u = 0;
printf("Please input your sentence:");
while((ch = getchar()) != '\n')
{
if(ch == 'a')
{
a++;
count++;
}
else if(ch == 'e')
{
e++;
count++;
}
else if(ch == 'i')
{
i++;
count++;
}
else if(ch == 'o')
{
o++;
count++;
}
else if(ch == 'u')
{
u++;
count++;
}
else
continue;
}
printf("There are %d vowels in this sentence\n", count);
printf("a(%d),e(%d),i(%d),o(%d),u(%d)\n",a,e,i,o,u);
return 0;
} gpf谦默 发表于 2018-9-8 09:36
你好在if() 里面的比较中用==而不是=
#include
哈哈,没注意到这个。。谢谢啦!
页:
[1]