So theres the exercise where it should read number of word that begins with vowels, consonant, and one that doesn't fit neither categories. So far my code is :
#include <iostream>
int main()
{
using namespace std;
char a;
cout << "Enter words (q to quit)\n";
cin.get(a);
int others = 0;
int vowels =0;
int consonant =0;
while (a != 'q')
{
cin.get(a);
if(isalpha(a)) {
switch (a) {
case 'a':
case 'i':
case 'u':
case 'e':
case 'o':
vowels++;
break;
default:
consonant++;
break;
}
}
else {
others++;
}
}
cout << vowels << " words beginning with vowels\n";
cout << consonant << " words beginning with consonant\n";
cout << others << " others";
return 0;
}
But it doesn't read the beginning of the word. Heres an example :
Enter words (q to quit)
The 12 awesome oxen ambled quietly across 15 meters of lawn. q
9 words beginning with vowels
11 words beginning with consonant
7 others.
Where is the problem here ?
EDIT: Its done now. If anyones interested
#include <iostream>
#include <cstring>
#include <cctype>
int main()
{
using namespace std;
string a;
cout << "Enter words (q to quit)\n";
int others = 0;
int vowels =0;
int consonant =0;
cin >> a;
while (a != "q")
{
cin >> a;
if(isalpha(a[0])) {
switch (a[0]) {
case 'a':
case 'i':
case 'u':
case 'e':
case 'o':
vowels++;
break;
default:
consonant++;
break;
}
}
else {
others++;
}
}
cout << vowels << " words beginning with vowels\n";
cout << consonant << " words beginning with consonant\n";
cout << others << " others";
return 0;
}
Thanks for all the suggestions