FLAMES Using C++

About: I'm pursuing an engineering degree in Information Technology from PSG College of Technology in Coimbatore, India. I'm the current Joint Secretary of the Information Technology Association at his University. ...

Hello friends, We all know about the flames game. Lol, It's one of the funniest games that made our childhood more happier. In this instructable, we are going to see how to code a flames program using the C++ language.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Concepts Used

Here I used the Circular doubly linked list.

Step 2: Main Function

int main()
{  
string name1,name2;
  int n1,n2;
  cout<<"ENTER FIRST NAME:";
  getline(cin,name1);
  cout<<"ENTER SECOND  NAME:";
  getline(cin,name2);
}

First, we need to get the two names with space so I use the getline() function to get the string with space.

Step 3: How to Omit Special Characters?

void emit(string &a)
{
 
 for(int i=0;a[i]!='\0';i++) 
 {
    
      if(a[i]>='a'&&a[i]<='z') {}
      else if(a[i]>='A'&&a[i]<='Z'){} 
      else
      
         a[i]='0';
  
} 
}

Now, we need to remove the special characters like &, $, ' ' ...etc. By using this function we removed all characters other than alphabets. Here, instead of removing, I replace it with '0'.

Step 4: Removing Same Characters

 for(i=0;name1[i]!='\0';i++)
   
for(j=0;name2[j]!='\0';j++)
      
 if((name1[i]==name2[j] || name1[i]==name2[j]+32))
      
 {
          
     name1[i]='0';
           
     name2[j]='0';
          
      break;
       
}

It is the first step of the flames game, That we need to remove the same characters that present in the two names. This code snippet helps us to replace the same characters by '0' and it also works well even it contains both the uppercase and lower case. The break statement helps us to avoid the removal of repeating characters.

j=0;<br>for(i=0;name1[i]!='\0';i++)
     
     if(name1[i]!='0')
        
          j++;
  
for(i=0;name2[i]!='\0';i++)
      
     if(name2[i]!='0')
        
          j++;
if(j==0)<br>    cout<<"NO FLAMES";

Here, we remove all '0's that are present in both names. Therefore, finally, all the same, characters are removed. Then the j is incremented that it is the count of the letters that are present in both names after removing the same characters. Now we need to check whether it contains at least one character or not. To make the code efficient we need to tell there is no possibility to play the flames game if it contains no unique characters.

Step 5: Creating Circular Doubly Linked List

string a="flames";

First, create a global string that contains "flames".

typedef struct node<br>{
    
    char data;
    
    node *next,*prev;
}node; 
node *top=NULL,*temp;

Now, create a structure that contains a character data, next address pointer, and previous address pointer.

Then create a pointer that points towards the top of the linked list.

node* ins(char a)<br>{
    
node *new1;
    
new1=new node;
    
new1->data=a;
    
new1->next=NULL;
    
new1->prev=NULL;
    
if(top==NULL)
    
{
        
      top=new1;
        
      temp=top;
}
    
else
   
{
        
temp->next=new1;
        
new1->prev=temp;
       
 temp=new1;
    
}
   
 return top; 
}

Then, insert the "flames" string into the doubly linked list by characterwise.

void check(int j)<br>{      
int count1,flag=0;      
for(int i=0;a[i]!='\0';i++)     
    
top=ins(a[i]);
}

Step 6: Code to Play the Flames

void check(int j)
{
    
int count1,flag=0;
    
for(int i=0;a[i]!='\0';i++)
    
    top=ins(a[i]);
   
 node *cur=top,*prev1;
    
temp->next=top;
   
 top->prev=temp;
    
while(1)
    
{
    
   count1=1;
   
    while(count1<j)
{
       cur=cur->next;
        
       count1++;
   
 }
    
node *temp1=cur;
   
 prev1=cur->prev;
    
cur->prev->next=cur->next;
    
cur->next->prev=cur->prev;
    
temp1->next=NULL;
    
free(temp1);
   
 cur=prev1->next;
    
node *test=cur;
    
if(test->data==test->next->data)
        
break;
    
}
}

we need to run the circular list that is the "flames" string according to the count of unique characters. Then we need to remove the character in "flames" that coincide with the count. We should realize the usage of a doubly linked list in this code snippet. It helps a lot to remove a particular character. It removes continuously. Until it reaches the condition that the same characters come repeatedly.

if(test->data==test->next->data)
break;

Step 7: Tell the Result

switch(cur->data)

{

case 'f':cout<<"FRIENDS&&";

break;

case 'l':cout<<"LOVE<3";

break;

case 'a':cout<<"AFFECTION$";

break;

case 'm':cout<<"MARRIAGE:)";

break;

case 'e':cout<<"ENEMY:(";

break;

case 's':cout<<"SIBLING";

break; }

Use this switch statement to tell the final result that is the last character remains after removing all other characters according to the count.

Now you can play flames easily by just entering the names, It's funny right. Play this game using your friend's names and make them angry LOL. Thank you.

Step 8: Code for Flames

The complete code for FLAMES is available here,

https://github.com/naveeen684/Flames-code-using-C-/tree/master

Be the First to Share

    Recommendations

    • Instrument Contest

      Instrument Contest
    • Make it Glow Contest

      Make it Glow Contest
    • STEM Contest

      STEM Contest

    Discussions