C++ Program to convert lower case to upper case

In this program, you will learn to convert lower case characters to upper case characters in C++.

Uppercase Character

An uppercase character is an alphabet character written in capital letters. For example, C. ASCII values of all 26 uppercase alphabet characters are 65-90. Where 65 is the ASCII value of A, 66 is the ASCII value of B, and so on up to, 90 is the ASCII value of Z

Lowercase Character

A lowercase character is an alphabet character written in small letters. For example, c. ASCII values of all 26 lowercase alphabet characters are 97-122. That is, a→97, b→98, c→99, and so on.

How to convert lower case character to upper case character

Since the ASCII value of a (capital letter) is 97 and the ASCII value of A (small letter) is 65. The difference between them is 32. Therefore, on subtracting 32 from the ASCII value of a small letter say a, then we'll get the ASCII value of its equivalent letter in uppercase. That is,
97 (ASCII value of a) - 32 = 65 (ASCII value of A)

C++ program to convert lower case characters to upper case character

The program asks the user to enter a lower case character. Read the entered character into the character type variable lowerch. Initialize the ASCII value of the entered character to the integer type variable asciivalue.
asciivalue = lowerch;
Then subtract 32 from the ASCII value and update the value of the variable asciivalue. The updated value is the ASCII value of the upper case of the entered character.
asciivalue = asciivalue - 32;
Get the updated value and print the character corresponding to the value on the screen

Algorithm

Step 1: Call the header file iostream.

Step 2: Use the namespace std.

Step 3: Open the integer type main function; int main().

Step 4: Declare two-character type variables upperch and lowerch and integer type                     variable asciivalue;

Step 5: Ask the user to enter an upper case character;

Step 6: Read the character into the variable lowerch;

Step 7: Get the ASCII value of the character to the variable asciivalue;

Step 8: subtract 32 from the asciivalue;

Step 9: Convert  the updated value of asciivalue to the character and get it into the                       variable upperch;

Step 10: Print the character in upperch;

Step 11:Exit 

C++ Source Code

                                          #include<iostream>
using namespace std;
int main()
{
    char upperch, lowerch;
    int asciivalue;
    cout<<"Enter a lowercase Character : ";
    cin>>lowerch;
    asciivalue =lowerch;
    asciivalue = asciivalue-32;
    upperch = asciivalue;
    cout<<"\nIts uppercase: "<<upperch;
    cout<<endl;
    return 0;
}
                                      

OUTPUT

Enter a lowercase Character : g
Its uppercase: G