C++ Program to convert upper case to lower case

In this program, you will learn to convert upper case characters to lower 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 upper case character to lower case character

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

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

The program asks the user to enter an uppercase character. Read the entered character into the character type variable upper. Initialize the ASCII value of the entered character to the integer type variable asciivalue.
asciivalue = upperch;
Then add 32 to the ASCII value and update the value of the variable asciivalue. The updated value is the ASCII value of the lower 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 upperch;

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

Step 8: add 32 to the asciivalue;

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

Step 10: Print the character in lowerch;

Step 11:Exit 


 

C++ Source Code

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

OUTPUT

Enter an uppercase Character : D
Its Lowercase: d