C语言之统计输入字符数量

这个程序市委了统计所输入的数字或者英文字母的数字的数量,当然稍加改动便可以统计特殊字符的个数,在此不再冗叙。
代码如下:

#include 

using namespace std;

int main()
{
     char ch;
     int numberInt=0,numberChar=0;
    cout<<"Please input character \n"<cin>>ch;
    numberInt++;
    numberChar++;
    while(ch!='#'){
        if(ch>'0'&&ch<'9'){
            ch=ch-'0'+1;
            cout<"Not a character,Please input corrected character\n"<cin>>ch;
            numberInt++;
        }else{
            cout<<"You really input the character\t"<cin>>ch;
            numberChar++;
        }
    }
    cout<<"code end !"<cout<<"you type numbers for %d numbers"<cout<<"you type character for %d numbers"<return 0;
}

你可能感兴趣的:(c/c++)