Flames game. need help please

need help in making this work

Page 1 of 1

8 Replies - 8812 Views - Last Post: 03 August 2009 - 04:48 AM Rate Topic: -----

#1 lex_12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-May 08

Flames game. need help please

Post icon  Posted 11 May 2008 - 06:58 AM


#include<stdio.h>
#include<string.h>


main(){

	char str1[30];
	char str2[30];
	int x,y,m,n,i;

	printf("Enter a name: \n");
	gets(str1);


	printf("Enter another name: \n");
	gets(str2);
		
		
		
		for(x=0;x>-1;x++){
			for(y=strlen(str1);y>-1;y--)
			if(strcmp(str1[x],str1[y]!=0))
				continue;
			
			else
			
			m=strlen(str1[x]+str1[y]); //i need to add them if they have the same char
				
			}return 1;
		

				//i think this is for checking the second string if they have the same characters	
		for(x=0;x>-1;x++){
			for(y=strlen(str2);y>-1;y--)
			if(strcmp(str1[x],str1[y]!=0))
				continue;
			
			else
			
			n=strlen(str1[x]+str2[y]);
				
			}return 1;
				
			
			i = m+n%6;
		


	switch(i){
			case 0:printf("Sweethearts\n");
		break;
			case 1:printf("Lovers\n");
		break;
			case 2:printf("Anger\n");
		break;
			case 3:printf("Marriage\n");
		break;
			case 4:printf("Enemies\n");
		break;
			case 5:printf("Friends\n");
		break;
		}
   
	
}




Is This A Good Question/Topic? 0
  • +

Replies To: Flames game. need help please

#2 Ambercroft  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 129
  • Joined: 05-January 07

Re: Flames game. need help please

Posted 11 May 2008 - 03:10 PM

What you should do is try to compile the code. You will find many errors at this point. Fix them then you will find that it won't run because of logical errors.

Then you can ask how to fix the code to make it do what you want. I can fix it but it definitely won't do what you want it to do. B)
Was This Post Helpful? 0
  • +
  • -

#3 lex_12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-May 08

Re: Flames game. need help please

Posted 12 May 2008 - 06:01 AM

ok.. thnx ambercroft.. i modified my code a bit because as you said there were alot of logical errors.. i simplified it to this.. but i think my algorithm is bit off.

Can anyone help me with an algorithm that will compare str1 and str2 and then count the number of the same characters they have and modulo it by 6. Any help or idea will be very much appreciated.


#include<stdio.h>
#include<string.h>


main(){

	char str1[30];
	char str2[30];
	int x,y,m,i;

	printf("Enter a name: \n");
	gets(str1);


	printf("Enter another name: \n");
	gets(str2);
		
		
		
		for(x=0;strlen(str1)<x);x++){
			for(y=strlen(str2);y>-1;y--){
			if(strcmp(str1[x],str2[y]==0))
			
			
				m=m+1;
				break;
			}
	}
			
			
				
		
			i = m+n%6;
		


	switch(i){
			case 0:printf("Sweethearts\n");
		break;
			case 1:printf("Friends\n");
		break;
			case 2:printf("Lovers\n");
		break;
			case 3:printf("Anger\n");
		break;
			case 4:printf("Marriage\n");
		break;
			case 5:printf("Enemy\n");
		break;
		}
   
	
}
		


Was This Post Helpful? 0
  • +
  • -

#4 Ambercroft  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 129
  • Joined: 05-January 07

Re: Flames game. need help please

Posted 12 May 2008 - 07:37 PM

Ok, If your code is clear it will most likely help you find your way. Any code I help on gets formatted to my liking which helps me understand and correct problems.

Take your calcuation for string length out of the loop. It won't matter for code speed here but build good habits.

strl1 = strlen(str1);
strl2 = strlen(str2);

Your comparison is mixed. x will always be larger. Try 'x < strl1', in English 'Do the code in the brackets because this comparison of x < strl1 is still true'.

Do the same in the other loop.

Get rid of 'n',break(only in the for loop) declare all variables.

Look up 'gets' and find out why you should replace it with 'fgets'.

Try all this and post the working code :)

This post has been edited by Ambercroft: 12 May 2008 - 07:43 PM

Was This Post Helpful? 0
  • +
  • -

#5 christian0159  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-September 08

Re: Flames game. need help please

Posted 28 September 2008 - 06:24 AM

i cant get it i got a problem can convert int to constant character
here what i write

#include<stdio.h>
#include <conio.h>
#include <string.h>

int main()
{
char str1[30], str2[30];
int x,y,strl1,strl2,i,n;
int m=0;
clrscr();
printf("name for boy\n");
gets(str1);
printf("\nname for girl\n");
gets(str2);
strl1=strlen(str1);
strl2=strlen(str2);

			   for(x=0 x<strl1; x++){
				   for(y=0 y<strl2; y++){
				   if(strcmp(str1[x],str2[y])==0)
				   
				   m=m+1;
					}
		}
n=m/6;
i=m-n;

switch(i) {
		   case 0:printf("Sweetheart\n");
		   break;
		   case 1:printf("Friends\n");
		   break;
		   case 2:printf("Lovers\n");
		   break;
		   case 3:printf("Anger\n");
		   break;
				   case 4:printf("Marriage\n");
		   break;
		   case 5:printf("Enemy\n");
		   break;
		   }
getch();
}


This post has been edited by christian0159: 28 September 2008 - 06:41 AM

Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,217
  • Joined: 23-August 08

Re: Flames game. need help please

Posted 28 September 2008 - 08:52 AM

if(strcmp(str1[x],str2[y])==0)


str1[x] and str2[y] aren't strings, they're individual characters in their respective character arrays, so you should just compare them for equality:

if (str1[x] == str2[y]) 
    ++m;


Was This Post Helpful? 0
  • +
  • -

#7 christian0159  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-September 08

Re: Flames game. need help please

Posted 29 September 2008 - 01:35 AM

thx for the help but there is still problem on it

here is my code

#include <stdio.h>
#include <conio.h>
#include<string.h>

void main()
{
char str1[30], str2[30];
int x,y,i,strl1,strl2;
int m=0;
clrscr();
printf("boy name\n");
gets(str1)
printf("girl name\n");
gets(str2);
strl1=strlen(str1);
strl2=strlen(str2);

for(x=0; x<strl1; x++){
for(y=0; y<strl2; y++){
if(str1[x]==str2[y])
++m;
}
}
i=m%

if(i==0 && m==0){
printf("No letters match FLAMES can be used");
{
if(i==0 && m!=0){
printf("Sweethearts");
{
if(i==1){
printf("Friends");
}
if(i==2){
printf("Lovers");
}
if(i==3){
printf("Anger");
}
if(i==4){
printf("Marriage");
}
if(i==5){
printf("Enemy");
}
getch();
}




I try to compare "aas" to "adf" it conclusion said Lovers but counting them
it should be 3 so Anger because the game add all the same letters and add their total so it count aaa so 3 if i try "aaggs" to "agagthh" total should be 8
m=8 i=m%6 so its 3 Anger also

This post has been edited by christian0159: 29 September 2008 - 03:56 AM

Was This Post Helpful? 0
  • +
  • -

#8 ungazzz  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 04-October 08

Re: Flames game. need help please

Posted 04 October 2008 - 11:57 PM

Here try this:



/*code ni ungazzz*/
#include <stdio.h>
#include <string.h>

char name1[100],name2[100],name11[100],name12[100];
int x,y,z,a;
int num,rep,rep2;
int len1,len2;

main() {
clrscr();
rep=0;
printf("Input the first name: ");
gets(name1);
strupr(name1);
printf("Input the 2nd name: ");
gets(name2);
strupr(name2);
y=0;
/* for checking of names */
len1=strlen(name1);
len2=strlen(name2);
rep=0;
for(x=0;x<len1;x++){
  if(name1[x]=='.') {
	name1[x]=' ';}
  if(name1[x]=='/') {
	name1[x]=' ';}
  for(y=0;y<len2;y++){
	 if((name1[x]==name2[y])&&(name2[y]!=' ')&&(name1[x]!=' ')) {
	num++;
	   for(z=0;z<len1;z++) {
		  if((name1[x]==name1[z])&&(x!=z)&&(name1[x]!=' ')&&(name1[z]!=' ')) {
		  num++;
		  name1[z]=' ';
		  }
	   }/*end for z*/
	   for(a=0;a<len2;a++) {
		  if((name1[x]==name2[a])&&(name1[x]!=' ')&&(name2[a]!=' ')&&(rep==0)) {
		  num++;
		  rep++;
		  name2[a]=' ';
		  }
		  if((name1[x]==name2[a])&&(name1[x]!=' ')&&(name2[a]!=' ')&&(rep>0)) {
		  num++;
		  name2[a]=' ';
		  }
	   }/*end for a*/
	   rep=0;
	 }/*end if*/
  }/*end for y*/
}/*end for x*/
rep2=num;
do {
  num=num-6;   }
while (num>6);
printf("\n\nThe total number of letters you both have is %d",rep2);
printf("\n\nYour compatability is: ");
if((rep2==0)&&(num==0))
  printf("Incompatible");
if((rep2>0)&&(num==0))
  printf("Friends");
if(num==1)
  printf("Friends");
if(num==2)
  printf("Lovers");
if(num==3)
  printf("Anger");
if(num==4)
  printf("Marriage");
if(num==5)
  printf("Enemy?");
if(num==6)
  printf("SSSS");
getch();
} 



change it if you want....or tell me if there are bugs

This post has been edited by ungazzz: 05 October 2008 - 12:02 AM

Was This Post Helpful? 1
  • +
  • -

#9 stc043  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-August 09

Re: Flames game. need help please

Posted 03 August 2009 - 04:48 AM

i have made a little post about "flames" in C++ ! hope it helps http://stcize.kilu.d...the-flame-in-c/

*** MOD EDIT: Changed URL to be visible, rather than shortened, for security purposes ***
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1