Я написал программу, которая читает ввод слова одновременно, пока не будет введен одиночный «q». Затем программа сообщит о количестве слов, которые начинались с гласных, числа, которое начиналось с согласных, и число, которое не соответствует ни одной из этих категорий.нужна помощь отладка ввода символов
#include <iostream>
#include <cstdlib>
int main()
{
char ch;
bool cont = true; //for controlling the loop
bool space = false; //see if there is a space in the input
int i = 0; //checking if the input is the first word
int consta, vowel, others;
consta = vowel = others = 0;
std::cout<<"Enter words (q to quit)\n";
while (cont && std::cin>>ch) //continue while cont is true and the input succeded
{
if (i == 0) //check if this is the first word
{
if (isalpha(ch))
if ((ch == 'a' ||ch == 'e' ||ch== 'i' ||ch== 'o' ||ch== 'u') || (ch == 'A' ||ch== 'E' ||ch== 'I' ||ch== 'O' ||ch== 'U'))
++vowel;
else
++consta;
else
++others;
++i; //add 1 to i so this if statement wont run again
}
if (space == true) //check if the last input was a space
{
if (!isspace(ch)) //check if the current input is not a space
{
if (ch != 'q') //and ch is not 'q'
{
if (isalpha(ch))
if ((ch == 'a' ||ch == 'e' ||ch== 'i' ||ch== 'o' ||ch== 'u') || (ch == 'A' ||ch== 'E' ||ch== 'I' ||ch== 'O' ||ch== 'U'))
++vowel;
else
++consta;
else
++others;
space = false;
}
}
else
cont = false;
}
if (isspace(ch)) //check if ch is a space
space = true;
}
std::cout<<"\n"<<consta<<" words beginnig with constants\n";
std::cout<<vowel<<" words beginnig with vowels\n";
std::cout<<others<<" words beginning with others\n";
system("pause");
return 0;
}
Но это не заканчивается, когда я ввожу пробел и «q». Но если я в положить «^ Z» это прекратить, но constantans всегда 1, а остальные всегда 0.
Пожалуйста, взгляните на мое решение – Saksham
. Что-то не так с моим решением. По крайней мере, комментарий был бы оценен за то, что он даже не поддержал мой ответ – Saksham