C Program to Design Love Calculator

By | October 18, 2019
C Program to Design Love Calculator

Here in this article, we have written a C program, to build a Love Calculator.

This program asks the user to enter his and his partner name and the program will use logic and calculate the love percentage between the entered names.

Vamware

The logic of Love calculator is basically adapted from the pen and paper games, and this program is only for fun.

Steps:

  • Ask user to enter his her : (sam)
  • Ask user to enter his partner name: (sofi)
  • According to the alphabets numbering take the sum of user, his partner name, and LOVE. (sam = 19 + 1 +13 = 33), (sofi = 19 + 15 + 6 + 9 = 49), (Love = 12 + 15 + 22 + 5 =  54)
  • Add each digit of the sums individually. (sam = 33 = 3+3= 6 ), (sofi = 49 = 4+9= 13)
  • Use the addition operation to Sum of Digits. (6+13 =19)
  • Sum the Sum of Digit and Love Sum and take (19 + 54 = 73)
  • Love percentage would be the sum of Love sum and Sum of Digits. (73% for Sam and Sofi)

C Program for Love Calculator: 

#include<ctype.h>
#include<stdio.h>
#include <conio.h>
#include<string.h>

int Sum_of_Digits(int digit)
    {
       int sum =0;
       while(digit > 0)
          {
              sum +=(digit%10);
              digit/=10;
          }
        return sum;
    }

void main()
 {
      char name[100], partner[100];
      int p,ns = 0, ps =0,love =54,i,j,love_percentage, opt;
      clrscr();

     do
     {
         printf("Enter Your Name: ");
         gets(name);

         printf("Enter Your Partner Name: ");
         gets(partner);

         for(i =0; i<strlen(name); i++)
            {
               ns += (tolower(name[i])-96);
            }

         for(j = 0; partner[j] != '\0'; j++)
            {
                ps+=(tolower(partner[j])-96);
            }
          p= Sum_of_Digits(ns);
          love_percentage = (Sum_of_Digits(ns)+Sum_of_Digits(ps)+love);
          printf("The Love Percentage is %d", love_percentage);
          printf("\nPress 1 To continue or 0 to Exit: ");
          scanf("%d",&opt);

    }while(opt!=0);
    getch();
}

Output:

Enter your Name: Sam
Enter your Partner Name: Sofi
The Love Percentage is 73
Press 1 To continue or 0 to Exit: 0

Leave a Reply

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