char ch;
int ecount=0, vowels=0, other=0;
cin.get(ch);
while(!cin.eof())
{ switch(ch)
{ case ‘e’:
ecount++;
case ‘a’: case ‘i’:
case ‘o’: case ‘u’:
vowels++;
break;
default:
other++;
}//end switch
cin.get(ch);
}//end while
cout %26lt;%26lt; ecount %26lt;%26lt; “ e’s, ” %26lt;%26lt; vowels %26lt;%26lt; “ vowels, and ”
%26lt;%26lt; other %26lt;%26lt; “ other characters. “ %26lt;%26lt; endl;
Need helpunderstanding what this c++ program does.?
It counts the number of e's, vowels, and other characters inputed and then displays the totals on the screen.
Reply:Looks like this would read in a characters until end of file is reached. It counts total number of letter "e"s, total vowels (including e's I think), and total non-vowels or "other characters".
Then it outputs the counts of each.
Reply:The user inputs a letter...the program keeps count of the # of 'e' that are entered with the variable ECOUNT.
VOWELS is the number of {a,e, i,o,u} are entered.
OTHER represents the number of other characters.
Example:
input:
a
e
e
b
c
u
e
output:
3 e's, 5 vowels, and 2 other characters.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment