C++ Program to convert upper case to lower case


January 31, 2023, Learn eTutorial
1184

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

Uppercase Character

An uppercase character is an alphabet character written in capital letters. 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 is an alphabet written in small case letters. 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 characters to lower case?

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)

How to write a C++ program to convert upper case to lower case

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 lowercase 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 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