How to print emoji in C++ console

Hey learners, welcome to the tutorial on how to print the emojis on c++ console. In this tutorial, we would print some of the known emojis by using do..while loop and switch case.

What is an emoji?

Emoji is a small picture usually used to express the emotion of a person. These emojis are frequently used while chatting with another person. We can get a set of emojis in windows10 through the keyboard by holding the windows logo + .(period) at once. (You can click on any emoji while you are on your code editor, the emoji will be inserted automatically)

For mac, the same can be done by holding command+control+spacebar at once.

Explanation and Implementation:

step 1: We include all the required headerfiles and namespaces and we will start writing the main() function from which the execution starts.
step 2: we have to declare an integer type of variable to get the input(chosen number in the list) from the user. Then we will write a list of emotions to be displayed to the user and ask the user to choose a number from the given list using the cout. we will take the input from the user using the cin.
step 3: we will write the switch case in which it takes the integer value entered by the user as a parameter and accordingly the switch case will execute its respective case which will print the emoji.
step 4: These statements have to be looped for ‘n‘ number of times unless the user wants to exit. Therefore we use the do..while() looping statement. In do..while(), the statements inside it will execute once, and then after the statements will execute depending on the condition. Hence, do..while() loop is known as the exit-control loop.

C++ program to print emoji

#include <iostream>
using namespace std;
int main() {
    int n;
    do {
        cout<<"List of emojis:\n";
        cout<<"1. Angel\n2. Happy\n3. Smiling face with hearts\n4. Tears of Happiness\n";
        cout<<"5. Love\n6. Shocking\n7. Sad\n8. Cry\n9. EXIT\n";
        cout<<"Choose your option(To EXIT, choose '9'): ";
        cin>>n;
        switch(n) {
            case 1:
                cout<<" 👼 \n\n";
                break;
            case 2:
                cout<<" 😀 \n\n";
                break;
            case 3:
                cout<<" 😍 \n\n";
                break;
            case 4:
                cout<<" 😂 \n\n";
                break;
            case 5:
                cout<<" 🖤 \n\n";
                break;
            case 6:
                cout<<" 😲 \n\n";
                break;
            case 7:
                cout<<" 😢 \n\n";
                break;
            case 8:
                cout<<" 😭 \n\n";
                break;
            case 9:
                exit(0);
        }
    } while(n!=9);
}

OUTPUT:

How to print emoji in C++ console

Leave a Reply

Your email address will not be published. Required fields are marked *