C++ Program to count number of uppercase, lowercase


In this program, You will learn how to count number of uppercase, lowercase, whitespaces and special symbol in C++.


Code@#343 C++

Total number of uppercase alphabets =2

Total number of lowercase alphabets =3

Total number of digits =3

Total number of white spaces =1

Total number of special symbols =4


Example: How to count number of uppercase, lowercase in C++

Run it Now
#include<iostream>
using namespace std;

int main() {

    char a[100];

    int i = 0, up = 0, lo = 0;
    int dig = 0, spc = 0, sym = 0;

    cout << "Enter String :";
    cin.getline(a, 100);

    while (a[i] != '\0') {
        i++;
    }

    for (int j = 0; j < i; j++) {

        if (a[j] >= 65 && a[j] <= 90) {
            up++;
        } else if (a[j] >= 97 && a[j] <= 122) {
            lo++;
        } else if (a[j] >= 48 && a[j] <= 57) {
            dig++;
        } else if (a[j] == 32) {
            spc++;
        } else {
            sym++;
        }
    }

    cout << "\nUppercase :" << up;
    cout << "\nLowercase :" << lo;
    cout << "\nDigits :" << dig;
    cout << "\nWhite Spaces :" << spc;
    cout << "\nSpecial Symbols :" << sym;

    return 0;
}

Output:

Enter String :John #$245 4
Uppercase :1
Lowercase :3
Digits :4
White Spaces :2
Special Symbols :2