#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#define alluser 2
#define allcriteria 5
#define character 20
#define first 0
#define second 1
void main()
{
clrscr();
welcome_screen();
fill_in_your_information();
show_your_data();
show_other_data();
fill_in_otherinformation(char sex);
percentage = compare_n_calculate();
show_the_result(double percentage);
getch();
}
void welcome_screen()
{
printf("\n\t ");
printf("\n\t ***** ***** ");
printf("\n\t ******* *** ******* ");
printf("\n\t ******* * ******* ");
printf("\n\t ******* ******* ");
printf("\n\t ******* ****** ");
printf("\n\t ***** ***** ");
printf("\n\t *** *** ");
printf("\n\t ** ** ");
printf("\n\t * * ");
printf("\n\t * ");
printf("\n\t ");
printf("\n\t Match Making Program ");
printf("\n\t Please press enter to go to next page ");
getch();
}
char fill_in_your_information()
{
int i;
for(i=0;i<45;i++) { printf("*"); } // *******************************
printf("\tEnter your information"); // Header for filling in your information
for(i=0;i<45;i++) { printf("*"); }
char sex;
i = 0;
while(sex != 'm' || sex != 'f'// if sex it not m or f , it will continue running till user put m or f
{
printf("Are you male or female? (M for Male and F for Female)");
scanf("%c",&sex);
if(sex != 'm' || sex != 'f'printf("Error. Please you enter the wrong key"); // If the user doesnt put M or F, it will show error
i++;
}
return sex;
struct profile{ // use for create structure for profile
char name[character];
int age;
char nationality[character];
};
struct profile user[alluser];
printf("Please enter your username :"); // Enter your user name in structure
scanf("%s",&user[first].name);
printf("Please enter your age :"); // Enter your age in structure
scanf("%d",&user[first].age);
printf("Please enter your nationality :"); // Enter your nationality in structure
scanf("%d",&user[first].nationality);
return user[first];
}
void show_your_data()
{
clrscr();
printf("================================================");
printf(" Your Criteria ");
printf("================================================");
int i=0;
char h;
FILE *fp;
fp = fopen("d:\\data.txt","r"); // use to open question data
{
while (!feof(fp)) // while not end of file, continue
{
h = fgetc(fp);
printf("%c",h); // print out the data from data.txt
i++;
}
fclose(fp);
}
int k;
int yourcriteria[1][allcriteria];
for( k=0;k<allcriteria;k++)
{
printf("Please enter what kind of person do you want :"); // Ask user to type in information
scanf("%d",&yourcriteria[0][k]);
if(yourcriteria[0][k] <= 0 || yourcriteria[0][k] >3 ) printf("Error, you can put only 1,2 or 3"); // if enter wrong number, print error.
}
}
char fill_in_otherinformation(char sex)
{
printf("================================================");
printf(" Input your partner information ");
printf("================================================");
if(sex == 'm'printf("I hope you are a lucky guy, now it a girl turn to input their information.");
if(sex == 'f'printf("I hope you are a lucky girl, now it a guy turn to input their information.");
struct profile{
char name[character];
int age;
char nationality[character];
};
struct profile user[2];
printf("Please enter your username :"); // Enter your user name in structure
scanf("%s",&user[1].name);
printf("Please enter your age :"); // Enter your age in structure
scanf("%d",&user[1].age);
printf("Please enter your nationality :"); // Enter your nationality in structure
scanf("%d",&user[1].nationality);
return user[1];
}
void show_other_data()
{
printf("================================================");
printf(" Your Partner Criteria ");
printf("================================================");
int i=0;
char c;
FILE *fp;
fp = fopen("d:\\infor.txt","r"); // use to open question data
{
while (!feof(fp)) // while not end of file, continue
{
c = fgetc(fp);
printf("%c",c); // print out the data from data.txt
i++;
}
fclose(fp);
}
int j;
int othercriteria[1][allcriteria];
for( j=0;j<allcriteria;j++)
{
printf("Please enter what kind of person do you want :"); // Ask user to type in information
scanf("%d",&othercriteria[0][j]);
if(othercriteria[0][j]0 <= 0 || othercriteria[0][j] >3) printf("Error, you can put only 1,2 or 3"); // if enter wrong number, print error.
}
}
double compare_n_calculate()
{
int j;
double total = 0;
double percentage;
for( j=0;j<5;j++)
{
if( othercriteria[0][j] == yourcriteria[0][j] ) // if both criteria are equal
{
total = total + 1; // then total + 1
}
else
{
total = total + 0; // if both criteria are not equal, total + 0
}
}
percentage = (total/allcriteria)*100; // calculate percentage from choosing criteria
printf("%.2lf%",percentage);
return percentage;
}
double show_the_result(double percentage)
{
int i;
for(i=0;i<45;i++) { printf("*"); } // *******************************
printf("\tResult table");
for(i=0;i<45;i++) { printf("\n*"); }
printf("\nName:\t%s\t%s",user.name[0],user.name[1]);
printf("\nAge:\t%s\t%s",user.age[0],user.age[1]);
printf("\nNationality:\t%s\t%s",user.nationality[0],user.nationality[1]);
for(i=0;i<45;i++) { printf("*"); }
printf("\n\tThe percentage is :",percentage);
for(i=0;i<45;i++) { printf("*"); }
if(percentage >= 75) printf("You are perfect match"); //condition to print out the result(predict from what they choose)
if(50 <= percentage < 75) printf("You will get along well");
if(30 <= percentage < 50) printf("You may have some problem");
if(percentage < 30) printf("Find someone else !!!");
}