# Love Calculator in C++ Programming and its Algorithm

Love calculator or a compatibility calculator is basically a simple calculator program that calculates the compatibility between two person on the basis of their names and dates of birth (extra details may be asked by the programmer). Love Calculator (which is logically a simple programming calculator) can be created using any programming language or script. A love calculator sometimes is also refereed to as Friendship Calculator.

In this tutorial we are going to create a simple calculator using C++ Programming Language. Take a look at the following algorithm to understand how it works.

C++ Love Calculator Program

## Algorithm of Love Calculator

STEP 1: Program asks for details (names of love couple) i.e. name1 and name2.

STEP 2: Program will then add name2 variable to name1 i.e. name1=name1+name2;

STEP 3 (Optional Step): Program will then eliminate common words from name1 variable i.e. APPLEMANGO will become APLEMNGO (Just to make it more complex, so that normal users can’t manually guess our love calculation formula).

STEP 4: Now each letter of name1 variable is converted from Char to Int (ASCII* values).

STEP 5: Now the sum of all the individual letters of name1 variable is divided by 101 and remainder is noted down (division by 101 ensures that at the end we’ll have a remainder smaller than or equal to 100).

STEP 6: The remainder is our compatibility or love percentage. Hurrree!

STEP 7: FINISH.

* ASCII (American Standard Code for Information Interchange): Computers don’t deal with text or graphics. The text (or anything) entered to a computer is converted to numbers at different levels. Simply understand that  when you press ‘a’ the ASCII value computer get is 97 and for b value is 98 and so on. For “A” value is 65 and B=66, C=67. Now the Funny thing, 0 means 48 in ASCII and 1 means 49 and so on. Read about Character Encoding to understand this stuff. We are going to take advantage of ASCII to convert a name into number, so that we can calculate some arithmetic value which we’ll call love percentage.

## Working of Love Calculator  Explained

Love at the image, we are entering two names i.e. Abc & Cde respectively. Now the follwoing STEPS shows the background work by the program.

STEP 1: name1=Abc and name2=Cde;
STEP 2: name1=name1+name2 then name1=ABCDE; (tally these steps with above steps)
STEP 3: name1=ABCDE (common letters are eliminated).
STEP 4: sum=A+B+C+D+E i.e. sum=65+66+67+68+69;
STEP 5: sum/101 and lefts a remainder 32;
STEP 6: COMPATIBILITY PERCENTAGE=32;
STEP 7: FINISH.

## Love Calculator in C++ Programming

```// C++ project on Love calculator or Compatibility Checker
// Website : https://himanshunegi.org/

#include<iostream.h>
#include<conio.h>       // gotoxy(), clrscr()
#include<string.h>
#include<ctype.h>
#include<stdio.h>
#include<stdlib.h>
#include<dos.h>          // for delay()

void main()		// Execution starts from here THE MAIN FUNCTION
{
char n1[30], n2[15];		// n1 means name1 and n2 means name2
clrscr();
textcolor(RED);
textbackground(LIGHTRED);

gotoxy(12,2);
cout<<"LOVE  CALCULATOR";

// STEP1
gotoxy(8,8);
gotoxy(8,10);
cout<<"Enter Crush Name :";

gotoxy(28,8);
gets(n1);
gotoxy(28,10);
gets(n2);

// STEP2
strcat(n1,n2);	// copying name2 into name1
for(int i=0; i<strlen(n1); i++)		// Converting all letter to uppercase
n1[i]=toupper(n1[i]);

// STEP3 OPTIONAL CODE
for(int k=0; k<strlen(n1); k++)		// Eliminating common letters
{
for(int i=0; i<strlen(n1); i++)
{
for(int j=0; j<strlen(n1); j++)
{
if(i==j)
continue;
else if(n1[i]==n1[j])
n1[j]=n1[j+1];
}
}
}
// STEP3 FINISHED

int sum=0;

// STEP-4
for(int l=0; l<strlen(n1); l++)	// Assigning ASCII value to each letter A=65, B=66 and so on
sum+=n1[l];

gotoxy(8,15);
cout<<"LOVE COMPATIBILITY : ";

/* Now Generating random percentage for a while to confuse the user
and make it interesting */

randomize();
for(int p=0; p<150; p++)
{
gotoxy(31,15);
cout<<random(100)<<" %";
delay(30);
}

// STEP-5
gotoxy(31,15);			// Giving the actual Percentage
cout<<sum%101<<" %   GUARANTEED !";
getch();		// Holds screen until a key is pressed

}         // END OF PROGRAM```

Now at this stage, I’m realizing that the program code is not that simple but it’s interesting. I have given you some ideas to make it little interesting by adding few extra features like eliminating common characters in the name, displaying random love percentage for few second to create suspense etc..

As you know this is just a sample program developed by me in C++ but I hope you’ll add more functionality to this program. You can develop better and  efficient algorithm than this which may have some logic and practical fact. But my aim is accomplished here, to provide you with a basic idea on the topic. I hope I had successfully taught you how to create a love calculator in c++ programming language which is a little interesting than a normal love calculator.

If you have any suggestions or you are facing problem in this code then comment below!

Similar Tutorial: Love Calculator in Visual Basic (VB6)

So have you learned something from this C++ Programming Tutorial? Are you able to create your own C++ Love Calculator?

## Join the discussion

1. vivek pandey

how to convert alphabet to ASCII in c++ programs

2. Himanshu Negi

@ Vivek Pandey

solution mailed to you !

To convert Alphabet into Ascii code just save alphabets into integers

int x=0; // let x is 0 (Zero)
char ch=’a’;

x=ch;

now x is equal to 97 (ASCII value of small case ‘a’)

3. RAJU SINGH

I WANT PROGRAM OF LOVE %AGE CLACULATOR IN C LANGUAGE.