#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

int arr[5], n=4;
clock_t start, end;
double time_taken;
void easy(), hard();
char input, choice;
FILE * fPointer;
int main(void)
{
	start=clock();
	printf("WELCOME TO MASTERMIND!\n");
	printf("\nDifficulty: [E]asy/[H]ard:\n");
	beginning:
	scanf("%c", &input);
	
	if(input=='E' || input=='e')
		{
		printf("\nEasy mode. None of the digits repeat.\n");
		easy();
		end=clock();
	time_taken = (end-start)/CLOCKS_PER_SEC;
	printf("\nTime taken: %f seconds\n", time_taken);
	fPointer = fopen("save.txt", "w");
	fprintf(fPointer, "%f", time_taken);
	fclose(fPointer);
		}
	

	else if(input=='H' || input=='h')
		{
		printf("\nHard mode. Digits might repeat\n");
		hard();
		end=clock();
		time_taken = (end-start)/CLOCKS_PER_SEC;
		printf("\nTime taken: %f seconds\n", time_taken);
		fPointer = fopen("save.txt", "w");
		fprintf(fPointer, "%f", time_taken);
		fclose(fPointer);
		}
	
	else 
	goto beginning;
	
	printf("\n\nPlay again? [y/n]: ");
	again:
	scanf("%c", &choice);
	switch(choice)
	{
		case 'y': printf("\nDifficulty: [E]asy/[H]ard:\n") ; goto beginning; 
		case 'n': return 0;
		default: goto again;
	}
	return 0;
}


void easy()
{
	int x, ran[4];
		srand(time(NULL));


		ran[0]=rand() %10;
		
		check2:
		ran[1]=rand() %10;
		if( ran[1]!=ran[0])	
		{
		}
		
		else goto check2;		
	
	  check3:
	  	ran[2]=rand() %10;
	  	if((ran[2]!=ran[1] )&& (ran[2]!=ran[0]))
	  	
	  		{	
		    }
		else goto check3;	  	

	  	ran[3]=rand() %10;
	  	if((ran[3]!=ran[2]) && (ran[3]!=ran[1]) && (ran[3]!=ran[0]))
	  		{
		  	}
	  
	  for(x=0;x<4;x++)
	  {
	  	printf("%i", ran[x]);
	  }

}


void hard()
{
		int x, ran[4];	
		srand(time(NULL));
		
		for(x=0;x<4;x++)
		{
			ran[x]=rand() %10;
			printf("%i", ran[x]);
		}
	
}
