C while loop - code won't work

后端 未结 2 1026
轻奢々
轻奢々 2021-01-22 08:48

I\'ve been writing a simple program to check if input letter is a vowel, and my code doesn\'t work. The program should take characters as input one by one until % is entered, wh

2条回答
  •  不要未来只要你来
    2021-01-22 09:50

    Presumably you're entering a character and then hitting [ENTER]. So, in actuality you are entering two characters -- the letter you typed and a line feed (\n). The second time through the loop you get the line feed and find that it's not a letter, so you hit the error case. Perhaps you want to add something like:

    if (processed == '\n') {
        continue;
    }
    

提交回复
热议问题