Hotel Management Program

I have made a program for hotel management. It has a problem that:
In the Accounts function, it should reset all the flags of the registered members through the program. But there is a error that it does NOT.
I have spent a lot of weeks, trying to debug this problem, but i couldn’t. So please help me.
Here is the code of the account function,

    void accounts()
{
	int ttt=0;
	struct person payment;
	char aname[21], oname[21];
	char *namea;
	int chec=1, ver=0;
	long int recsize;
	recsize=sizeof(payment);
	f=fopen("C:\\HOTEL.DAT", "rb+");
	if(f == NULL){
		clrscr();
		cprintf("File could not be opened!");
		sleep(4);
		exit(0);
	}
	clrscr();
	cprintf("\n                   *** Pearl Guest House - Payments ***\n\n");
	cprintf("\r\r\rEnter the Name :");
	fflush(stdin);
	scanf("%[^\n]s", &aname);
	namea=strupr(aname);
	strcpy(oname, namea);
	while(fread(&payment, recsize, 1, f) == 1){

		if((payment.flag == 1) && (strcmp(payment.name,oname) == 0)){
			payment.pay=1;
			printf("\n\n Payment Received");
			fflush(stdin);
			getch();
			ver=1;

			fseek(f, -recsize, SEEK_CUR);
			fwrite(&payment, sizeof(payment), 1, f);
			break;

		}

	}

	if(ver!=1){
		printf("\n\n Record not Found!!!");
		fflush(stdin);
		getch();
	}
	//rewind(f);
	fclose(f);
	f=fopen("C:\\HOTEL.DAT", "rb+");
	if(f == NULL){
		clrscr();
		cprintf("File could not be opened!");
		sleep(4);
		exit(0);
	}

	while(fread(&payment, recsize, 1, f) == 1){
		if(payment.pay==0){
			chec=0;
			break;
		}
	}
	//rewind(f);
	f=fopen("C:\\HOTEL.DAT", "rb+");
	if(f == NULL){
		clrscr();
		cprintf("File could not be opened!");
		sleep(4);
		exit(0);
	}

	if(chec==1){
			while(fread(&payment, recsize, 1, f) == 1){
				payment.pay=0;
				fseek(f, -recsize, SEEK_CUR);
				fwrite(&payment, recsize, 1, f);
				ttt++;
				printf("%d", ttt);
			}

			printf("\n\n All payments recieved...\n\nSo, the payments flags are set to 0");
			fflush(stdin);
			getch();
	}
	printf("Before Fclose");
	fclose(f);
	printf("After Fclose");
}

Please help ASAP.
Eagerly waiting for an answer.
Thanks in advance.
Daksh Shah