check if whole string is uppercase

To check if a whole string is uppercase in C++, you can iterate through each character of the string and check if it is an uppercase letter. Here's the step-by-step explanation:

  1. Start by including the necessary header file at the beginning of your code: cpp #include <cctype> This header file provides functions for character handling, including the function we'll use to check if a character is uppercase.

  2. Declare a string variable to hold the input string. For example: cpp std::string inputString = "YOUR_STRING"; Replace "YOUR_STRING" with the actual string you want to check.

  3. Iterate through each character of the string using a loop. You can use a for loop or a range-based for loop. Here's an example using a range-based for loop: cpp bool isUppercase = true; for (char c : inputString) { // Check if the character is not uppercase if (!std::isupper(c)) { isUppercase = false; break; } }

  4. Inside the loop, use the std::isupper() function from the <cctype> header to check if each character is uppercase. The function returns a non-zero value if the character is uppercase, and zero otherwise.

  5. If a character is found that is not uppercase, set the isUppercase variable to false and break out of the loop. This means that the string is not entirely uppercase.

  6. After the loop, you can use the isUppercase variable to determine if the whole string is uppercase. If it is true, then the string is entirely uppercase. Otherwise, it contains at least one non-uppercase character.

Here's the complete code example:

#include <iostream>
#include <cctype>

int main() {
    std::string inputString = "YOUR_STRING";
    bool isUppercase = true;

    for (char c : inputString) {
        if (!std::isupper(c)) {
            isUppercase = false;
            break;
        }
    }

    if (isUppercase) {
        std::cout << "The string is entirely uppercase." << std::endl;
    } else {
        std::cout << "The string is not entirely uppercase." << std::endl;
    }

    return 0;
}

Replace "YOUR_STRING" with the actual string you want to check. After running the code, it will output whether the string is entirely uppercase or not.