BEFORE
[IMG]http://www.daniweb.com/forums/attachment.php?attachmentid=22439&d=1317523788[/IMG]
#include<iostream.h>
#include<string.h>
#include<conio.h>
int findSimilar(char[],char[]);
void checkValue(int,int);
int main(){
char boy[50];
char girl[50];
int similarInBoy=0;
int similarInGirl=0;
int total;
clrscr();
cout<<"Enter Boy's Name: ";
cin.getline(boy,50);
cout<<"Enter Girl's Name: ";
cin.getline(girl,50);
similarInBoy=findSimilar(boy,girl);
similarInGirl=findSimilar(girl,boy);
total=similarInGirl+similarInBoy;
cout<<"Boy: "<<similarInBoy<<",";
checkValue(similarInBoy,1);
cout<<"\n";
cout<<"Girl: "<<similarInGirl<<",";
checkValue(similarInGirl,2);
cout<<"\n";
cout<<"Total: "<<total<<",";
checkValue(total,3);
cout<<"\n";
getch();
return 0;
}
void checkValue(int similar,int gender){
if(gender==1){
if(similar>6)
similar%=6;
switch(similar){
case 1:
cout<<"Friend";
break;
case 2:
cout<<"Love";
break;
case 3:
cout<<"Affair";
break;
case 4:
cout<<"Married";
break;
case 5:
cout<<"Enemy";
break;
case 6:
cout<<"Sweetheart";
break;
}
}
else if(gender==2){
if(similar>6)
similar%=6;
switch(similar){
case 1:
cout<<"Friend";
break;
case 2:
cout<<"Love";
break;
case 3:
cout<<"Affair";
break;
case 4:
cout<<"Married";
break;
case 5:
cout<<"Enemy";
break;
case 6:
cout<<"Sweetheart";
break;
}
}
else{
if(similar>12)
similar%=12;
switch(similar){
case 1:
cout<<"Friends";
break;
case 2:
cout<<"Lovers";
break;
case 3:
cout<<"Affair";
break;
case 4:
cout<<"Marriage";
break;
case 5:
cout<<"Enemies";
break;
case 6:
cout<<"Sweethears";
break;
}
}
}
int findSimilar(char firstName[],char secondName[]){
int len;
int len2;
int similar=0;
char ch1,ch2;
char* first;
char *second;
first=strupr(firstName);
second=strupr(secondName);
len=strlen(firstName);
len2=strlen(secondName);
for(int ctr=0;ctr<len;ctr++){
ch1=first[ctr];
for(int ctr2=0;ctr2<len2;ctr2++){
ch2=second[ctr2];
if((ch1!=' ')&&(ch1==ch2)){
similar++;
break;
}
}
}
return similar;
}
AFTER
[IMG]http://www.daniweb.com/forums/attachment.php?attachmentid=22440&d=1317523788[/IMG]
#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
int findSimilar(char[],char[]);
void checkValue(int,int);
int main(){
char boy[50];
char girl[50];
int similarInBoy=0;
int similarInGirl=0;
int total;
clrscr();
printf("Enter Boy's Name: ");
gets(boy);
fflush(stdin);
printf("Enter Girl's Name: ");
gets(girl);
fflush(stdin);
similarInBoy=findSimilar(boy,girl);
similarInGirl=findSimilar(girl,boy);
total=similarInGirl+similarInBoy;
printf("Boy: ",similarInBoy);
printf(",");
checkValue(similarInBoy,1);
printf("\n");
printf("Girl: ",similarInGirl);
printf(",");
checkValue(similarInGirl,2);
printf("\n");
printf("Total: ",total);
printf(",");
checkValue(total,3);
printf("\n");
getch();
return 0;
}
void checkValue(int similar,int gender){
if(gender==1){
if(similar>6)
similar%=6;
switch(similar){
case 1:
cout<<"Friend";
break;
case 2:
cout<<"Love";
break;
case 3:
cout<<"Affair";
break;
case 4:
cout<<"Married";
break;
case 5:
cout<<"Enemy";
break;
case 6:
cout<<"Sweetheart";
break;
}
}
else if(gender==2){
if(similar>6)
similar%=6;
switch(similar){
case 1:
cout<<"Friend";
break;
case 2:
cout<<"Love";
break;
case 3:
cout<<"Affair";
break;
case 4:
cout<<"Married";
break;
case 5:
cout<<"Enemy";
break;
case 6:
cout<<"Sweetheart";
break;
}
}
else{
if(similar>12)
similar%=12;
switch(similar){
case 1:
cout<<"Friends";
break;
case 2:
cout<<"Lovers";
break;
case 3:
cout<<"Affair";
break;
case 4:
cout<<"Marriage";
break;
case 5:
cout<<"Enemies";
break;
case 6:
cout<<"Sweethearts";
break;
}
}
}
int findSimilar(char firstName[],char secondName[]){
int len;
int len2;
int similar=0;
char ch1,ch2;
char* first;
char *second;
first=strupr(firstName);
second=strupr(secondName);
len=strlen(firstName);
len2=strlen(secondName);
for(int ctr=0;ctr<len;ctr++){
ch1=first[ctr];
for(int ctr2=0;ctr2<len2;ctr2++){
ch2=second[ctr2];
if((ch1!=' ')&&(ch1==ch2)){
similar++;
break;
}
}
}
return similar;
}