就学了while loop,if else,reverse那些。。。
今天学了点continue/break, switch case的。。。lecturer讲有点不清楚。。。头脑有点难消化
有点问题想问。。。
write a C++ program to count the numbers of vowels and consonants in a word
- #include<iostream>
- using namespace std;
- int main()
- {
- int i=0,vowels=0,spaces=0,consonants=0;
- char text[50];
- cout<<"Enter the word\n";
- cin>>text;
- while(i<strlen(text))
- {
- switch(text[i])
- {
- case 'a':
- case 'e':
- case 'i':
- case 'o':
- case 'u':
- vowels++;
- break;
- default:
- consonants++;
- break;
- }
- i++;
-
- }
- cout<<"Number of vowels="<<vowels<<"\n";
- cout<<"Number of consonants="<<consonants<<"\n";
- return 0;
- }
然后i<strlen(text)是什么来的?
[ 本帖最后由 虚空使者 于 2008-12-22 04:23 PM 编辑 ]





