my prof ask us to make a code for the game FLAMES using function oriented program.wherein the prog. will count the number of same letters to be cancelled in each name and will print the result.
ex.
julie ann :2
mjhay :2
marry
i dont know whats wrong w/ my code.here it is:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int cancelled();
int cancelled2();
int equiv(int cancelled,int cancelled2);
main()
{
char yn[30],hn[30];
int m,q,z,v,n;
clrscr();
printf("enter her name: ");
gets(yn);
printf("\nenter his name: ");
gets(hn);
/*to unable upper cases*/
for(m=0;m<strlen(yn);m++)
{
if(isupper(yn[m]))
{ yn[m]=tolower(yn[m]);
}
for(q=0;q<strlen(yn);q++)
{
if(isspace(yn[q]))
{ yn[q]='.'; }
}
}
for(z=0;z<strlen(hn);z++)
{
if(isupper(hn[z]))
{ hn[z]=tolower(hn[z]);
}
for(v=0;v<strlen(yn);v++)
{
if(ispunct(hn[v]))
{ hn[v]=' '; }
}
}
printf("\ncancelled in her name : %i\n\n",(int)cancelled);
printf("canclled in his name : %i\n\n",(int)cancelled2);
n=equiv((int)cancelled,(int)cancelled2);
/*to print result*/
if(n==1||n==7||n==13||n==19||n==25)
{
printf("friends");
}
else if(n==2||n==8||n==14||n==20||n==26)
{
printf("lovers");
}
else if(n==3||n==9||n==15||n==21||n==27)
{
printf("angry");
}
else if(n==4||n==10||n==16||n==22||n==28)
{
printf("marry");
}
else if(n==5||n==11||n==17||n==23||n==29)
{
printf("enemy");
}
else if(n==6||n==12||n==18||n==24||n==30)
{
printf("friends");
}
getch();
}
int cancelled()
{ char yn[30],hn[30];
int a,b,u;
float ctr1=0.0;
for(a=0;a<strlen(yn);a++)
{
for(b=0;b<strlen(hn);b++)
{
if(yn[a]==hn[b])
{
ctr1=ctr1+1;
for(u=0;u<strlen(hn);u++)
{
if(hn[b]==hn[u]&&u!=b)
{
ctr1=ctr1-0.5;
}
}
}
}
}
return ctr1;
}
int cancelled2()
{ char yn[30],hn[30];
int c,d,u;
float ctr2=0.0;
for(c=0;c<strlen(hn);c++)
{
for(d=0;d<strlen(yn);d++)
{
if(hn[c]==yn[d])
{
ctr2=ctr2+1;
for(u=0;u<strlen(hn);u++)
{
if(yn[d]==yn[u]&&u!=d)
{
ctr2=ctr2-0.5;
}
}
}
}
}
return ctr2;
}
int equiv(int cancelled,int cancelled2)
{ int n;
n=cancelled+cancelled2;
return n;
}
this code will have a result of:
cancelled in her name:1015
cancelled in his name: 1162
wherein its wrong.please help me.:)