#include <stdio.h>

void main()
{
int age=40,guess,count=0;
FILE *fp;
int high;
printf("Guess my age:");
scanf("%d",&guess);
count=count+1;

while(age!=guess)
{
printf("Guess my age:");
scanf("%d",&guess);
count=count+1;
}

printf("\nWell done you took %d guesses\n\n",count);

fp=fopen("highscore.txt","r");//read from file
fscanf(fp,"%d",&high);
fclose(fp);

if(count<=high)
{
printf("Well done! New high score\n\n");
fp=fopen("highscore.txt","w");
fprintf(fp,"%d",count);//write new high score
fclose(fp);
}
else
{
printf("Sorry no high score this time");
}



}