soln3_2.cpp
来自「Wrox.Ivor.Hortons.Beginning.Visual.C.Plu」· C++ 代码 · 共 46 行
CPP
46 行
// Soln3_2.cpp
/*
nVowels records the count of vowels and nChars records the total number of
characters that are entered including vowels.
*/
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
char c;
int nVowels=0, nChars=0;
cout << "Enter characters and enter 'Q' or 'q' to end:"
<< endl;
for (;;)
{
cin >> c;
if (c == 'q' || c == 'Q')
break;
switch(c)
{
case 'A': case 'a':
case 'E': case 'e':
case 'I': case 'i':
case 'O': case 'o':
case 'U': case 'u':
nVowels++; // This executes only when c is a vowel.
// Because there is no break statement here execution
// continues with the default case.
default:
nChars++; // This is always executed
}
}
cout << "Total chars=" << nChars << ", vowels=" << nVowels;
cout << endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?