{
char c = getchar();
string vowels("aeiouAEIOU");
if (vowels.find(c) != string::npos)
{
cout << c << " is a vowel" << endl;
}
else
{
cout << c << " is not a vowel" << endl;
}
}
I suppose you start by getting a sentence. You only extract a single character from your input stream. (Well, that's true of the original code. In the latest code you extract two characters and discard the first.)
How would I fix something like this:
It is without the is a vowel or is not a vowel, still doesn't work but how do I fix it?
cire wrote:
I suppose you start by getting a sentence.
You can do that a char at a time if you desire, but to do that you still need to extract more than one or two char's total.
You might start by forgetting about vowels and consonants and simply outputting the chars as you would process them. Once you've got that down, build on it.
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
int main()
{
char c;
int Uc = 0, Dc=0, Vc=0;
string vowels("aeiouAEIOU");
cout << "Enter a sentence: ";
cin.get(c);
while(c != '\n')
{
if(isupper(c))
Uc++;
cin.get(c);
{
if(isdigit(c))
Dc++; //
cin.get(c);
}
{
if(vowels.find(c) != string::npos)
Vc++;
cin.get(c);
}
}
cout << setfill ('.');
cout << " Number of uppercase letters" << right << setw(10) << Uc << endl;
cout << " Number of digits" << right << setw(20) << Dc << endl;
cout << " Number of vowels" << right << setw(20) << Vc << endl;
system("pause");
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
//This is what I have
Enter a sentence: Today Is Thr Jan, 2015
Number of uppercase letters.........3
Number of digits...................1
Number of vowels...................1
Press any key to continue . . .
//The output should look like this:
Enter a sentence: Today Is Thr Jan, 2015
Number of uppercase letters.........4
Number of digits....................4
Number of vowels....................4
Press any key to continue . . .
Why are you extracting a character twice within the loop? You test one character to see if it's uppercase or a digit, then you check another to see if it's a vowel.
, you're only reading a single character. You could try reading the entire sentence first, but if yu really want to do it one character at a time then do like so:
1 2 3
get a character
process it
repeat until no more characters