Print Name inside a Heart Shape in C++

I have written a code in C++ in which i have drawn a heart of hearts characters and printed name inside it entered by user.
Here is code of print name inside a heart shape in c++

Code:

#include <iostream>
#include <string>
#include<stdio.h>
 using namespace std;
int main()
{
    int i, j, n=20;
    string name;
    int len;

   cout<<"Enter your name: ";
cin>>name;

cout<<endl<<endl;
    len=name.length();

    // Print upper part of the heart shape
    for(i=n/2; i<=n; i+=2)
    {
        for(j=1; j<n-i; j+=2)
        {
           cout<<" ";
        }

        for(j=1; j<=i; j++)
        {
           cout<<char(3);
        }

        for(j=1; j<=n-i; j++)
        {
          cout<<" ";
        }

        for(j=1; j<=i; j++)
        {
           cout<<char(3);
        }

       cout<<endl;
    }

    // Prints lower triangular part of the pattern
    for(i=n; i>=1; i--)
    {
        for(j=i; j<n; j++)
        {
        cout<< " ";
        }

        // Print the name
        if(i == n)
        {
            for(j=1; j<=(n * 2-len)/2 -1 ; j++)
            {
                cout<<char(3);
            }

        cout<<" "<<name<<" ";

            for(j=1; j<=(n*2-len)/2 -1 ; j++)
            {
                cout<<char(3);
            }
        }
        else
        {
            for(j=1; j<=(i*2)-1; j++)
            {
             cout<<char(3);
            }
        }

       cout<<endl;
    }

    return 0;
}

Output:

Enter your name: Javeria


     ♥♥♥♥♥♥♥♥♥♥          ♥♥♥♥♥♥♥♥♥♥
    ♥♥♥♥♥♥♥♥♥♥♥♥        ♥♥♥♥♥♥♥♥♥♥♥♥
   ♥♥♥♥♥♥♥♥♥♥♥♥♥♥      ♥♥♥♥♥♥♥♥♥♥♥♥♥♥
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥    ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
 ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥ Javeria ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
 ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
   ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
    ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
     ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
      ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
       ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
        ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
         ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
          ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
           ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
            ♥♥♥♥♥♥♥♥♥♥♥♥♥♥♥
             ♥♥♥♥♥♥♥♥♥♥♥♥♥
              ♥♥♥♥♥♥♥♥♥♥♥
               ♥♥♥♥♥♥♥♥♥
                ♥♥♥♥♥♥♥
                 ♥♥♥♥♥
                  ♥♥♥
                   ♥

Related Post

Leave a Reply

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