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.:)

Recommended Answers

All 3 Replies

I've never heard of "Flames". Since you've had no responses, I suspect others haven't either.

What should your output be, and what have you tried to fix it, so we don't have to repeat it?

Thanks for using code tags. ;)

oh i see . .im sorry for that. .in the game flames it stands for:

F=FRIENDS
L=LOVERS
A=ANGRY
M=MARRIED
E=ENEMY
S=SWEETHEARTS

the game goes like this.

you get a couples name example:

julie ann
jan paul

and then compare the first name and the second name ..count the number of the same letters.there are 6 same letters in the first name(j,u,l,a,n,n)
6 in the 2nd name(j,a,n,a,u,l).add the # of sme letters.
so there are 12.

the result is SWEETHEARTS.


.. im sorry for not good explanation . .:)

if it is not in program oriented the code goes like this . .

#include<stdio.h>
#include<string.h>
#include<ctype.h>
main()
	{
	  char yn[30],hn[30],x;
	  int a,b,c,d,n,u;
	  float ctrA=0.0,ctrB=0.0;
	  clrscr();

	  printf("enter her name: ");
	  gets(yn);
	  printf("\nenter his name: ");
	  gets(hn);
	  strlwr(yn);
	  strlwr(hn);


/*to count the number of same letters*/



for(a=0;a<strlen(yn);a++)
{
for(b=0;b<strlen(hn);b++)
{ if(isspace(yn[a]))
{ a++;}
if(yn[a]==hn[b])
{
ctrA=ctrA+1;
for(u=0;u<strlen(hn);u++)
{
if(hn[b]==hn[u]&&u!=b)
{
ctrA=ctrA-0.5;
}
}
}
}
}


printf("\n\ncancelled in her name : %i\n\n",(int)ctrA);

for(c=0;c<strlen(hn);c++)
{
for(d=0;d<strlen(yn);d++)
{ if(isspace(hn[c]))
{c++;}
if(hn[c]==yn[d])
{
ctrB=ctrB+1;
for(u=0;u<strlen(yn);u++)
{
if(yn[d]==yn[u]&&u!=d)
{
ctrB=ctrB-0.5;
}
}
}
}
}
printf("cancelled in his name : %i\n\n",(int)ctrB);


	     n=ctrA+ctrB;
/*to print result*/
if(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();


	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.