Home » C solved programs » Advance C programs

C program to design love calculator



This program will read you and your partner's name and behalf on entered names program will calculate your love percentage. Since there is no such kind of logic to calculate the program, we made this program for fun only. This is a small game to pass your time by calculating love percentage between you and your partner. And off course you can also calculate the love percentage with others girl to see how much you love will success with your secrete partner. So enjoy the game.

Calculate Love Percentage using C program

/*C program to design love calculator.*/

#include <stdio.h>
#include <string.h>
#include <ctype.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 yName[40], pName[40];
	int sum, sum1, i, choice;
	float perc=0;

	do
	{
		printf("Enter your name: ");
		fflush(stdin);
		gets(yName);

		printf("Enter your partner's name: ");
		fflush(stdin);
		gets(pName);

		sum=0;
		for(i=0;i<(strlen(yName));i++)
		{
			sum+=tolower(yName[i]);
		}

		sum1=0;
		for(i=0;i<(strlen(yName));i++)
		{
			sum1+=tolower(pName[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 with some one else (0 to exit, 1 to continue) ???: ");
		scanf("%d",&choice);

	}while(choice!=0);

    return 0;
}
    
    Enter your name: Mike
    Enter your partner's name: Lilly
    Your love percentage is: 63.00

    Want to calculate with some one else (0 to exit, 1 to continue) ???: 1
    Enter your name: Mike
    Enter your partner's name: Rosy
    Your love percentage is: 59.00

    Want to calculate with some one else (0 to exit, 1 to continue) ???: 1
    Enter your name: Mike
    Enter your partner's name: Alessia
    Your love percentage is: 55.00

    Want to calculate with some one else (0 to exit, 1 to continue) ???: 0





Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.