You probably have calculated love percentage for yourself or your friend in your school and/or college. This article details a C program to design a love calculator.
The C program asks the user to enter his/her and his/her partner's name. Then the program will use logic and calculate the love percentage depending on the entered names. The logic of the love calculator is basically taken from the pen and paper games , and this program is only for fun.
Although nothing serious, it will help you understand how do and for loops work.
Steps to Create the Program
- Ask the user to enter his or her name. (Sam)
- Next, ask the user to enter his or her partner's name. (Sofi)
- According to the alphabets, take the sum of user, his partner name, and LOVE. (Sam = 19 + 1 +13 = 33 ), (Sofi = 19 + 15 + 6 + 9 = 49 ), and (Love = 12 + 15 + 22 + 5 = 54)
- Add each digit of the sums individually. (Sam = 33 = 3+3= 6 ) and (Sofi = 49 = 4+9= 13 )
- Use the addition operation to Sum of Digits. ( 6 + 13 = 19 )
- Add the Sum of Digit and Love. ( 19 + 54 = 73 )
- Love percentage would be the sum of Love and Sum of Digits. (73% for Sam and Sofi)
C Program to Design a 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
Conclusion
That concludes the simple C program to design a love calculator. It is a fun programming exercise that will help you to play with the loops - in this case, do and for - and understand them better.
People are also reading:
- C Program to Convert Feet into Inches
- Write a Program to Print the Truth Table for XY+Z
- Python Program to Make a Simple Calculator
- Write a C++ Program to Print a Man Using Graphics
- WAP to calculate area of a circle, a rectangle or a triangle
- Python Program to Find Armstrong Number in an Interval
- WAP to create a loading bar
- Pattern Program in C
- Python Program to Display the Multiplication Table
- WAP to Find Cube of a Number using Functions
- Python Program to Illustrate Different Set Operations
Leave a Comment on this Post