Advertisement
janac

Convert lowercase letters to uppercase

Nov 10th, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. // Convert lowercase letters to uppercase.
  5. int main()
  6. {
  7.     string word; // This is the input.
  8.  
  9.     cout << "Enter a word:" << endl;
  10.     cin >> word; // Get the word from the user.
  11.  
  12.      // Check each letter.
  13.     for (size_t i = 0; i < word.size(); ++i)
  14.     {
  15.         // If the letter is lowercase,
  16.         if (word[i] >= 97 && word[i] <= 122)
  17.         {
  18.             // Change it to uppercase.
  19.             word[i] = word[i] - 32;
  20.         }
  21.     }
  22.  
  23.     // Display the converted word.
  24.     cout << word << endl;
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement