C Program to implement love calculator

Love calculator

In this tutorial, we are going to see the program for love calculator. Love calculator program is only for entertainment.

For implementing such type of program we can use any logic such program has on predefined logic. It’s only implemented for fun.

In this program, we implement in a simple way using simple logic which is as follows

A logic for love calculator

  1. First, we take the name of girl and boy (partners ) to calculate their percentage of love.
  2. We calculate a sum of the value of each letter in girl name by using its ASCII values and store sum in sum1.
  3. Same for a boy name, we calculate a sum of a value of each letter in boy name by using its ASCII values and store in sum2.
  4. Now, we add each digit in sum1 and sum2 and sum with 40 to total.
  5. This resultant sum we can consider as the percentage of love between partners.

C Program to implement love calculator

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687#include <string.h> #include <ctype.h> #include <stdio.h>//function will return sum of all digits int sumOfDigits(int num) {     int sum=0;     while(num>0)     {         sum+=(num%10);         num/=10;     }     return sum; } int main() {     char your_nm[40], prtnr_nm[40];     int sum, sum1, i, choice;     float perc=0;     do     {        printf(“Enter your name: “);         fflush(stdin);         gets(your_nm);         printf(“Enter your partner’s name: “);         fflush(stdin);         gets(prtnr_nm);         sum=0;         for(i=0;i<(strlen(your_nm));i++)         {             sum+=tolower(your_nm[i]);         }         sum1=0;         for(i=0;i<(strlen(your_nm));i++)         {             sum1+=tolower(prtnr_nm[i]);         }         perc=(sumOfDigits(sum)+sumOfDigits(sum1))+40;         if(perc>100) perc=100;         printf(“Your love percentage is: %.02f\n\n”,perc);         printf(“Want to calculate again (0 to exit, 1 to continue) ???: “);         scanf(“%d”,&choice);     }while(choice!=0);     return 0; }

Output :

Love calculator
Love calculator

Explanation :

1. Start

2. Define a function to calculate sum of all digits .

3. Write a main function.

4. Declare variable

your_nm[40]  => to store your name

prtnr_nm[40]  => to store partner name

sum, sum1 => to store sum of digits

i, => temporary variable

choice => to take choice from user

per => to store percentage

5. Take couple name from user.

6. Calculate percentage (using above logic we used )

7. Print percentage.