#include "CS35lib.h"

void encode_it (char word[], char coded[])
{
	char letter;
	int counter;
	
	for (counter=0; counter <strlen(word) ;counter++ )
	{
		cout<<"Change letter "<<word[counter]<<" to: ";
		cin>>letter;
		coded[counter]=letter;
	}
	cout<<"This is the new word encoded "<<coded<<endl;
}	
void try_to_guess(char guess[], char word[])
{
	int counter = 0;
	int i,d=0,c;
	
	cout<<"Try to guess the origional word (No letter repetition) : ";
	cin>>guess;
	if(strlen(guess) !=  strlen(word))
		{
			cout<<"INVALID: Remember word is "<<strlen(word)<<" letters, so Try again: ";
			   cin>>guess;
		}
	while (counter < 5)
	{
		c = 0;
		for (i=0; i < strlen(word); i++)
		{
		   for(d=0; d < strlen(word); d++)
		   {	
		      if (guess[i] == word[d])
			  {
				  c++;
			  }
			     
		   }
	    }

		
		if ( c == strlen(word))
		{
			counter = 5;
			cout<<"YOU GOT IT !! \n";
		}
		else 
		{
		
		   cout<<"You have "<<c<<" correct letters from origional word ,try again: ";
		   cin>>guess;
		   if(strlen(guess) !=  strlen(word))
		{
			cout<<"INVALID: Remember word is "<<strlen(word)<<" letters, so Try again: ";
			   cin>>guess;
		}
		   
		}
	}
	
}


int main()
{
	int i=0;
	char word[8], new_word[8], guess[8];
	char letter;
	cout<<"Player 1: \n";
	cout<<"Enter a 5 letter word (No letter repetition): ";
	getline(word);
    encode_it (word, new_word);
	cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
	cout<<"This is the new encoded word: "<<new_word<<endl;
	cout<<"Player 2: \n";

	try_to_guess (guess, word);
	

	
	return 0;


}


