Prints uppercase equivalents of five lowercase letters. - C++ Data Type

C++ examples for Data Type:char

Description

Prints uppercase equivalents of five lowercase letters.

Demo Code

#include <iostream>
using namespace std;
int main()//  www. j a  v a2 s.  c  om
{
   char letter;
   int ctr;
   for (ctr=1; ctr<=5; ctr++)
   {
      cout << "Please enter a lowercase letter ";
      cin >> letter;
      if ((letter < 97) || (letter > 122))  // See if out-of-range.
      {
         continue;
      }              // Go get another
      letter -= 32;   // Subtract 32 from ASCII value. to get uppercase.
      cout << "The uppercase equivalent is " << letter << "\n";
   }
   return 0;
}

Result


Related Tutorials