I just finished up the final touches on my C Project (at least I hope that's the last of them). Anyway, it's due Friday (10% of my overall grade) and I'd like to have some quick feedback (constructive criticisms and complements) before I had it in. It was suppose to be a group project but my group members weren't on top of their game so I had to push and do all the work myself. A blessing in disguise I guess.

Enough of my chatter, evaluate my presumable complete hotel reservation and booking system.

If you want proper advice, you should post your code, not your executable.

One tip is: validate user input.

See attachment.

Attachments naamloos.JPG 32.11 KB

Ok, check out my source code file too.

Attachments
/* South Coast Serenity Inn (SSI) Automated Reservation and Booking System */

/*
FILE NAME:	SSI_SYSTEM.c
COMPILER:	Borland C++ 5.02

AUTHORS:		Julian Josephs		0601479
				Rommel Beckford
				Moyah Barr

DATE:			April, 2008
COURSE:		Programming Using C
TITLE:		Class Project

GROUP:		PBCMS 1
FACULTY:		SCIT			*/


// INCLUDED LIBRARIES
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>   // needed for time function
#include <string.h> // needed for string compare function
#include <dos.h>    // needed for sleep function
#include <ctype.h>  // needed for tolower function

// MACROS - Used in the local room_assigner function
#define TRUE 1
#define FALSE 0



/* ----------GLOBAL DATA----------- */

// STRUCTURES

// Structure for storing information about the rooms (ROOM_DATA)
typedef struct{
	int room_num;      // room number must be between 1 - 50 inclusively
   int room_type;     //1- smoking 2- non-smoking
   float room_rate;
   int room_status;   //9-reserve 10-vacant 12-occupied
	} ROOM_DATA;

// Structure for storing information about the guests (ADMISSION_DATA)
typedef struct{
	int reservation_num;
	int guest_num;
   char first_name[20];
   char MI[2];            // middle initial
   char last_name[20];
   int credit_card;       // credit card number
   int telephone;
   float charge;          // (bill) charge = room_rate * lengh_stay
	int cancel;            // 1 - no ,  2 - yes
   int length_stay;       // during of visit in days
   ROOM_DATA room_connec; // ROOM_DATA is a member of ADMISSION_DATA
   } 	ADMISSION_DATA;


// STRUCT NAME ASSIGNMENT - Initialization with blank data
static ADMISSION_DATA section={NULL,NULL,"","","",0,999,0.00,1,0};
static ROOM_DATA room={NULL,1,0.00,10};


// FUNCTIONS
void menu();
void addReserve();
void cancelReserve();
void checkin();
void checkout();
void incomereport();
void room_available_report();
void reservation_report();
void room_info_menu();         // includes add room data capability
void all_guests_report();      // list details of all reserved and checked-in guests

/* ----END OF GLOBAL DATA---- */



// MAIN FUNCTION
int main()
{
   menu();    // call to user main menu

   sleep(2);  // pauses screen for 2 seconds
   return 0;  // Retuns zero indicating successful program termination
} // END OF MAIN




// FUNCTION IMPLEMENTATIONS


/*  +++++++++MENU FUNCTION+++++++++ */
void menu()
{
	int choice;  // variable for storing user's choice

   do{
   	// clears the console of all output - system call works on Windows and Unix / Linux Systems
   	if( system( "cls" ) != 0 ) system( "clear" );

      // ASCII ART BANNER
      textcolor(4);   // specifies a particular colour for cprintf
      cprintf("+-+-+-+-+-+ +-+-+-+-+-+ +-+-+-+-+-+-+"); // cprintf is capable of printing statements in colour
      printf("\n");
      textcolor(13);
      cprintf("|S.o.u.t.h| |C.o.a.s.t| |S.y.s.t.e.m|");
      printf("\n");
      textcolor(4);
      cprintf("+-+-+-+-+-+ +-+-+-+-+-+ +-+-+-+-+-+-+");
      // END OF BANNER

      // Program menu with user prompt
      textcolor(14);
      printf("\n\n\n");
		cprintf("Welcome to South Coast Serenity Inn Guest Manangement System");
      printf("\n\n");
      textcolor(15);
   	cprintf("To Exit the Program, Select -1 Followed by the Enter or Return Key");
      textcolor(14);
      printf("\n\n");
   	cprintf("Please Select the Number For the Corresponding Request.\n");

      // USER OPTIONS
      textcolor(14); printf("\n"); cprintf("(1)"); printf("\t"); textcolor(15); cprintf("Add Reservation");
      textcolor(14); printf("\n"); cprintf("(2)"); printf("\t"); textcolor(15); cprintf("Cancel Reservation");
      textcolor(14); printf("\n"); cprintf("(3)"); printf("\t"); textcolor(15); cprintf("Guest Check-In");
      textcolor(14); printf("\n"); cprintf("(4)"); printf("\t"); textcolor(15); cprintf("Guest Check-Out");
      textcolor(14); printf("\n"); cprintf("(5)"); printf("\t"); textcolor(15); cprintf("Income Report");
      textcolor(14); printf("\n"); cprintf("(6)"); printf("\t"); textcolor(15); cprintf("Room Status Report");
      textcolor(14); printf("\n"); cprintf("(7)"); printf("\t"); textcolor(15); cprintf("Reservation Report");
      textcolor(14); printf("\n"); cprintf("(8)"); printf("\t"); textcolor(15); cprintf("Room Information Sub-Menu");
      textcolor(14); printf("\n"); cprintf("(9)"); printf("\t"); textcolor(15); cprintf("All Guests");
      // END OF USER OPTIONS

      textcolor(14); printf("\n\n"); cprintf("Enter Your Selection Now: ");
   	scanf("%d", &choice);

      if( system( "cls" ) != 0 ) system( "clear" );  // clears the console before displaying sub-menu

   	switch(choice)   // contains all global function calls
   	{
   		case 1:
      	addReserve();
         break;

      	case 2:
         cancelReserve();
         break;

      	case 3:
  			checkin();
         break;

      	case 4:
         checkout();
      	break;

      	case 5:
      	incomereport();
      	break;

      	case 6:
      	room_available_report();
      	break;

      	case 7:
      	reservation_report();
      	break;

         case 8:
         room_info_menu();
         break;

         case 9:
         all_guests_report();
         break;

      	default:
         textcolor(12); // sets unspecified colour prints to light red
      	(choice == -1?textcolor(10), cprintf("SSI SYSTEM SHUTTING DOWN"): cprintf("\nONLY 1 - 9 ARE  VALID OPTIONS"));
         sleep(3);
   	}

   }while(choice <= -2 || choice >= 0); // only -1 can end the menu function, hence returns control to main menu effectively closing the program
}



/* +++++++ADD NEW RESERVATION FUNCTION+++++++ */
void addReserve()
{
	int room_assigner(int, int); // local function for assigning a user to a room
	void create_reservations(); // local function for creating reservations.txt file
   char uoption;     // user's choice
   int res_num;      // reservation number assigned to a specific guest (1 - 50)
   FILE *reserver;   // reservations.txt file pointer
   srand(time(NULL)); // seeds rand function to generate guest number

   // fopen opens the reservations.txt file, attempts to create one if cannot be opened
   if((reserver=fopen("reservations.txt", "rb+"))==NULL)
   {
    	textcolor(12); cprintf("\nERROR!! FILE COULD NOT BE OPENED!"); sleep(3);
     	printf("\n");
      textcolor(10); cprintf("\nATTEMPTING TO CREATE RESERVATIONS FILE"); sleep(1);
      create_reservations(); // function call to generate reservations.txt file
   }
   else
   {
		printf("Welcome to the Add Reservation Section!");

		do{   // user prompt
            printf("\n\nEnter a reservation number: ");
            scanf("%d", &res_num);

            if( res_num > 0 && res_num < 51 ) // A maximum of 50 rooms can be reserved
            {
            	// sets the pointer to the reservation specified by the user
            	fseek( reserver, (res_num - 1) * sizeof ( ADMISSION_DATA ), SEEK_SET );
            	// reads a record from the file into the section structure
            	fread( &section, sizeof( ADMISSION_DATA ), 1, reserver );

            	// checks if record is blank
            	if(section.reservation_num != 0)
            	{
            		printf("\nA reservation already exits in this slot");
            	}
            	else
            	{
               	// user prompts
               	printf("\nEnter First Name: ");
               	scanf("%s",&section.first_name);

               	printf("\nEnter Middle Initial: %c");
               	scanf("%s", &section.MI);

               	printf("\nEnter Last Name: ");
               	scanf("%s",&section.last_name);

               	printf("\nEnter credit card number: ");
               	scanf("%d",&section.credit_card);

               	printf("\nCell, Home, or Work #: ");
               	scanf("%d", &section.telephone);

               	printf( "\nNumber of days of stay: " );
               	scanf("%d", &section.length_stay);

               	textcolor(10); printf("\n"); cprintf("DATA VERIFIED"); sleep(2);

            		printf("\n\nEnter room type (1 for smoking and 2 non-smoking): ");
         			scanf("%d", &section.room_connec.room_type);   //1-smoking 2-non-smoking

                  if( section.room_connec.room_type == 1 || section.room_connec.room_type == 2 )
                  {
               		// call to room_assigner function to locate and assigns a room - returns the number of the avaliable room
               		section.room_connec.room_num = room_assigner(section.room_connec.room_type, 9);

               		// zero indicates that a free room was not located
               		if(section.room_connec.room_num == 0)
               		{
               			printf("\n\nNo space avaliable");
               		}
               		else
               		{
               			textcolor(10); printf("\n"); cprintf("ROOM FOUND"); printf("\n\nYour Room Number is: %d", section.room_connec.room_num); sleep(2);

            				section.reservation_num = res_num;
                  		// random # is generated for guest
   							section.guest_num = rand()% (30000 - 1 + 1) + 1;

                  		// calculates bill based on room type and length of stay
                  		section.charge=((section.room_connec.room_type==1)?4000*section.length_stay:3000*section.length_stay);

                  		// moves file pointer to the correct record in the file
            				fseek( reserver, ( section.reservation_num - 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
                  		// writes contents of section into the record in file
         					fwrite( &section, sizeof( ADMISSION_DATA ), 1, reserver );
               		}
                  }
                  else
                  {
                  	textcolor(12); printf("\n"); cprintf("ONLY 1 AND 2 ARE VALID OPTIONS"); sleep(1);
                     textcolor(12); printf("\n\n"); cprintf("RESERVATION PROCESS ABORTED"); sleep(3);

It's kind of long in my view. That's why I didn't post it up in the first place but here it is:

/* South Coast Serenity Inn (SSI) Automated Reservation and Booking System */

/*
FILE NAME:	SSI_SYSTEM.c
COMPILER:	Borland C++ 5.02

AUTHOR:		knight fyre

DATE:			April, 2008
COURSE:		Programming Using C
TITLE:		Class Project

GROUP:		PBCMS 1
FACULTY:		SCIT			*/


// INCLUDED LIBRARIES
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>   // needed for time function
#include <string.h> // needed for string compare function
#include <dos.h>    // needed for sleep function
#include <ctype.h>  // needed for tolower function

// MACROS - Used in the local room_assigner function
#define TRUE 1
#define FALSE 0



/* ----------GLOBAL DATA----------- */

// STRUCTURES

// Structure for storing information about the rooms (ROOM_DATA)
typedef struct{
	int room_num;      // room number must be between 1 - 50 inclusively
   int room_type;     //1- smoking 2- non-smoking
   float room_rate;
   int room_status;   //9-reserve 10-vacant 12-occupied
	} ROOM_DATA;

// Structure for storing information about the guests (ADMISSION_DATA)
typedef struct{
	int reservation_num;
	int guest_num;
   char first_name[20];
   char MI[2];            // middle initial
   char last_name[20];
   int credit_card;       // credit card number
   int telephone;
   float charge;          // (bill) charge = room_rate * lengh_stay
	int cancel;            // 1 - no ,  2 - yes
   int length_stay;       // during of visit in days
   ROOM_DATA room_connec; // ROOM_DATA is a member of ADMISSION_DATA
   } 	ADMISSION_DATA;


// STRUCT NAME ASSIGNMENT - Initialization with blank data
static ADMISSION_DATA section={NULL,NULL,"","","",0,999,0.00,1,0};
static ROOM_DATA room={NULL,1,0.00,10};


// FUNCTIONS
void menu();
void addReserve();
void cancelReserve();
void checkin();
void checkout();
void incomereport();
void room_available_report();
void reservation_report();
void room_info_menu();         // includes add room data capability
void all_guests_report();      // list details of all reserved and checked-in guests

/* ----END OF GLOBAL DATA---- */



// MAIN FUNCTION
int main()
{
   menu();    // call to user main menu

   sleep(2);  // pauses screen for 2 seconds
   return 0;  // Retuns zero indicating successful program termination
} // END OF MAIN




// FUNCTION IMPLEMENTATIONS


/*  +++++++++MENU FUNCTION+++++++++ */
void menu()
{
	int choice;  // variable for storing user's choice

   do{
   	// clears the console of all output - system call works on Windows and Unix / Linux Systems
   	if( system( "cls" ) != 0 ) system( "clear" );

      // ASCII ART BANNER
      textcolor(4);   // specifies a particular colour for cprintf
      cprintf("+-+-+-+-+-+ +-+-+-+-+-+ +-+-+-+-+-+-+"); // cprintf is capable of printing statements in colour
      printf("\n");
      textcolor(13);
      cprintf("|S.o.u.t.h| |C.o.a.s.t| |S.y.s.t.e.m|");
      printf("\n");
      textcolor(4);
      cprintf("+-+-+-+-+-+ +-+-+-+-+-+ +-+-+-+-+-+-+");
      // END OF BANNER

      // Program menu with user prompt
      textcolor(14);
      printf("\n\n\n");
		cprintf("Welcome to South Coast Serenity Inn Guest Manangement System");
      printf("\n\n");
      textcolor(15);
   	cprintf("To Exit the Program, Select -1 Followed by the Enter or Return Key");
      textcolor(14);
      printf("\n\n");
   	cprintf("Please Select the Number For the Corresponding Request.\n");

      // USER OPTIONS
      textcolor(14); printf("\n"); cprintf("(1)"); printf("\t"); textcolor(15); cprintf("Add Reservation");
      textcolor(14); printf("\n"); cprintf("(2)"); printf("\t"); textcolor(15); cprintf("Cancel Reservation");
      textcolor(14); printf("\n"); cprintf("(3)"); printf("\t"); textcolor(15); cprintf("Guest Check-In");
      textcolor(14); printf("\n"); cprintf("(4)"); printf("\t"); textcolor(15); cprintf("Guest Check-Out");
      textcolor(14); printf("\n"); cprintf("(5)"); printf("\t"); textcolor(15); cprintf("Income Report");
      textcolor(14); printf("\n"); cprintf("(6)"); printf("\t"); textcolor(15); cprintf("Room Status Report");
      textcolor(14); printf("\n"); cprintf("(7)"); printf("\t"); textcolor(15); cprintf("Reservation Report");
      textcolor(14); printf("\n"); cprintf("(8)"); printf("\t"); textcolor(15); cprintf("Room Information Sub-Menu");
      textcolor(14); printf("\n"); cprintf("(9)"); printf("\t"); textcolor(15); cprintf("All Guests");
      // END OF USER OPTIONS

      textcolor(14); printf("\n\n"); cprintf("Enter Your Selection Now: ");
   	scanf("%d", &choice);

      if( system( "cls" ) != 0 ) system( "clear" );  // clears the console before displaying sub-menu

   	switch(choice)   // contains all global function calls
   	{
   		case 1:
      	addReserve();
         break;

      	case 2:
         cancelReserve();
         break;

      	case 3:
  			checkin();
         break;

      	case 4:
         checkout();
      	break;

      	case 5:
      	incomereport();
      	break;

      	case 6:
      	room_available_report();
      	break;

      	case 7:
      	reservation_report();
      	break;

         case 8:
         room_info_menu();
         break;

         case 9:
         all_guests_report();
         break;

      	default:
         textcolor(12); // sets unspecified colour prints to light red
      	(choice == -1?textcolor(10), cprintf("SSI SYSTEM SHUTTING DOWN"): cprintf("\nONLY 1 - 9 ARE  VALID OPTIONS"));
         sleep(3);
   	}

   }while(choice <= -2 || choice >= 0); // only -1 can end the menu function, hence returns control to main menu effectively closing the program
}



/* +++++++ADD NEW RESERVATION FUNCTION+++++++ */
void addReserve()
{
	int room_assigner(int, int); // local function for assigning a user to a room
	void create_reservations(); // local function for creating reservations.txt file
   char uoption;     // user's choice
   int res_num;      // reservation number assigned to a specific guest (1 - 50)
   FILE *reserver;   // reservations.txt file pointer
   srand(time(NULL)); // seeds rand function to generate guest number

   // fopen opens the reservations.txt file, attempts to create one if cannot be opened
   if((reserver=fopen("reservations.txt", "rb+"))==NULL)
   {
    	textcolor(12); cprintf("\nERROR!! FILE COULD NOT BE OPENED!"); sleep(3);
     	printf("\n");
      textcolor(10); cprintf("\nATTEMPTING TO CREATE RESERVATIONS FILE"); sleep(1);
      create_reservations(); // function call to generate reservations.txt file
   }
   else
   {
		printf("Welcome to the Add Reservation Section!");

		do{   // user prompt
            printf("\n\nEnter a reservation number: ");
            scanf("%d", &res_num);

            if( res_num > 0 && res_num < 51 ) // A maximum of 50 rooms can be reserved
            {
            	// sets the pointer to the reservation specified by the user
            	fseek( reserver, (res_num - 1) * sizeof ( ADMISSION_DATA ), SEEK_SET );
            	// reads a record from the file into the section structure
            	fread( &section, sizeof( ADMISSION_DATA ), 1, reserver );

            	// checks if record is blank
            	if(section.reservation_num != 0)
            	{
            		printf("\nA reservation already exits in this slot");
            	}
            	else
            	{
               	// user prompts
               	printf("\nEnter First Name: ");
               	scanf("%s",&section.first_name);

               	printf("\nEnter Middle Initial: %c");
               	scanf("%s", &section.MI);

               	printf("\nEnter Last Name: ");
               	scanf("%s",&section.last_name);

               	printf("\nEnter credit card number: ");
               	scanf("%d",&section.credit_card);

               	printf("\nCell, Home, or Work #: ");
               	scanf("%d", &section.telephone);

               	printf( "\nNumber of days of stay: " );
               	scanf("%d", &section.length_stay);

               	textcolor(10); printf("\n"); cprintf("DATA VERIFIED"); sleep(2);

            		printf("\n\nEnter room type (1 for smoking and 2 non-smoking): ");
         			scanf("%d", &section.room_connec.room_type);   //1-smoking 2-non-smoking

                  if( section.room_connec.room_type == 1 || section.room_connec.room_type == 2 )
                  {
               		// call to room_assigner function to locate and assigns a room - returns the number of the avaliable room
               		section.room_connec.room_num = room_assigner(section.room_connec.room_type, 9);

               		// zero indicates that a free room was not located
               		if(section.room_connec.room_num == 0)
               		{
               			printf("\n\nNo space avaliable");
               		}
               		else
               		{
               			textcolor(10); printf("\n"); cprintf("ROOM FOUND"); printf("\n\nYour Room Number is: %d", section.room_connec.room_num); sleep(2);

            				section.reservation_num = res_num;
                  		// random # is generated for guest
   							section.guest_num = rand()% (30000 - 1 + 1) + 1;

                  		// calculates bill based on room type and length of stay
                  		section.charge=((section.room_connec.room_type==1)?4000*section.length_stay:3000*section.length_stay);

                  		// moves file pointer to the correct record in the file
            				fseek( reserver, ( section.reservation_num - 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
                  		// writes contents of section into the record in file
         					fwrite( &section, sizeof( ADMISSION_DATA ), 1, reserver );
               		}
                  }
                  else
                  {
                  	textcolor(12); printf("\n"); cprintf("ONLY 1 AND 2 ARE VALID OPTIONS"); sleep(1);
                     textcolor(12); printf("\n\n"); cprintf("RESERVATION PROCESS ABORTED"); sleep(3);
                  }
            	}

            	section.reservation_num = 0;
               }
               else
               {
               	textcolor(12); printf("\n"); cprintf("RESERVATION NUMBER MUST BE GREATER THAN 0 AND LESS THAN 51"); sleep(6);
               }

            printf("\n\nDo you wish to continue? Any key for Yes, (n) for No: ");
            fflush(stdin); // clears input buffer
            scanf("%c",&uoption);
            if( system( "cls" ) != 0 ) system( "clear" );
      }while( tolower(uoption)!='n' );  // only the character 'n' can end the loop
	}
   fclose ( reserver ); // fclose closes the reservations.txt file
}



/* +++++++++CREATE NEW RESERVATION FILE FUNCTION+++++++++ */
void create_reservations()
{
	FILE *reserver; // reservations.txt file pointer
   int count = 1;

   // fopen opens reservations.txt file; exits if file cannot be opened
	if(( reserver = fopen( "reservations.txt", "wb" )) == NULL)
   {
   	textcolor(12); cprintf("\nERROR!! RESERVATION FILE COULD NOT BE CREATED!"); sleep(3);
   }
   else
   {  // output 50 blank records to the file
   	for(; count <=50; count++ )
      {
      	fwrite( &section, sizeof( ADMISSION_DATA ), 1, reserver );
      }
      textcolor(10); printf("\n\n"); cprintf("RESERVATION FILE SUCCESSFULLY CREATED"); sleep(3);
   }
   fclose( reserver );  // fclose closes the reservations.txt file
}



/* ++++++++ROOM ASSIGNMENT FUNCTION+++++++ */
int room_assigner(int type, int status) // type (1- smoking 2- non-smoking); status (9-reserve 10-vacant 12-occupied)
{
   FILE *roomPtr; // rooms.txt file pointer
	int r_num = 1; // room number
   int found = FALSE; // macro TRUE = 1, FALSE = 0
   int seeker = 1;  // traverses through each record

   // fopen opens the rooms.txt file, exits function if file cannot be opened
   if((roomPtr = fopen("rooms.txt", "rb+")) == NULL)
   {
   	textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
   }
   else
   {
   	do
      {  // seeker positions file pointer to correct record in file
      	fseek( roomPtr, ( seeker - 1) * sizeof( ROOM_DATA ), SEEK_SET);
         // reads record from the file into the room structure
         fread( &room, sizeof( ROOM_DATA ), 1, roomPtr );

         if( room.room_num != NULL )    // checks for blank record
         {
         	if( room.room_status == 10 )   // checks if room is avaliable
         	{
               // room type is smoking AND user selected smoking
            	if (room.room_type == 1 && type == 1)
            	{
            		room.room_rate = 4000; // smoking rate is $4000
               	room.room_num = room.room_num;
            		room.room_type = room.room_type;
            		room.room_status = status;
            		r_num = room.room_num; // assigns the available room to r_num

                  // seeker positions file pointer to correct record in file
            		fseek( roomPtr, ( seeker - 1) * sizeof( ROOM_DATA ), SEEK_SET);
                  // writes the contents of room is a record in the file
            		fwrite( &room, sizeof( ROOM_DATA ), 1, roomPtr );

               	found = TRUE; // assigns true when a room is found
               }

               // room type is non-smoking AND user selected non-smoking
            	if(room.room_type == 2 && type == 2)
            	{
            		room.room_rate = 3000;   // smoking rate is $3000
               	room.room_num = room.room_num;
            		room.room_type = room.room_type;
            		room.room_status = status;
            		r_num = room.room_num; // assigns the available room to r_num

                  // seeker positions file pointer to correct record in file
            		fseek( roomPtr, ( seeker - 1) * sizeof( ROOM_DATA ), SEEK_SET);
                  // writes the contents of room is a record in the file
            		fwrite( &room, sizeof( ROOM_DATA ), 1, roomPtr );

               	found = TRUE; // assigns true when a room is found
               }

               // available room type and desired type were not a match
            	if( room.room_type != type )
            	{
             		seeker++; // increments if not a match
            	}
         	}
         	else
         	{
         		seeker++; // increments if room not available
         	}
         }
         else
         {
         	seeker++; // increments if no data was set for that room
         }
      }while(found == FALSE && !feof(roomPtr)); // loop ends only if a empty room was found or the end of the file is reached
   }
   (( found == FALSE )? r_num = 0 : NULL ); // if feof occurs and found is still false, r_num is set to zero
   fclose ( roomPtr ); // fclose closes the rooms.txt file

	return r_num;  // return the choosen room, if zero then a room was not found
}



/* ++++++++CANCEL RESERVATION FUNCTION++++++++ */
void cancelReserve()
{
	FILE *reserver;  // reservations.txt file pointer
   FILE *roomPtr;   // rooms.txt file pointer
   FILE *logger;    // guest_history.txt file pointer
   int res_num;     // reservation number
   int rm_num;      // room number
   int confirm;

   // create ADMISSION_DATA with no information
   static ADMISSION_DATA res_remover={NULL,NULL,"","","",0,999,0.00,1,0};

   // fopen opens the file; exits if file cannot be opened
   if((roomPtr = fopen( "rooms.txt", "rb+" )) == NULL )
   {
   	textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
   }
   else
   {  // fopen opens the file; exits if file cannot be opened
   	if((reserver = fopen( "reservations.txt", "rb+")) == NULL)
   	{
   		textcolor(12); cprintf("\nERROR!! RESERVATION FILE COULD NOT BE OPENED!"); sleep(3);
   	}
   	else
   	{
      	printf("Welcome to the Cancel Reservation Section!");

   		printf("\n\nEnter reservation number to cancel: ");
   		scanf("%d", &res_num);

         // positions file pointer to the correct record in file
   		fseek( reserver, (res_num - 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
         // reads record from file in section structure
   		fread( &section, sizeof ( ADMISSION_DATA ), 1, reserver );

         // checks to see if reservation was made; # must be (1 - 50)
   		if( section.reservation_num == 0 )
   		{
   			textcolor(12); cprintf("\nINVALID!! RESERVATION DOES NOT EXIST!"); sleep(3);
   		}
   		else
  	 		{
         	// displays guest details for confirmation purposes
            printf("\n%d\t%s\t%s\t%d", section.reservation_num, section.first_name, section.last_name, section.credit_card);
            printf("\n\nConfirm Check-out? (1 for yes, 2 for no): ");
            scanf("%d", &confirm);

            if (confirm == 1)
            {
         		// fopen opens/creates the file for appending; exits if file cannot be opened/created
         		if((logger = fopen("guest_history.txt", "ab")) == NULL )
            	{
            		textcolor(12); cprintf("\nERROR!! HISTORY FILE COULD NOT BE CREATED!"); sleep(3);
            	}
            	else
            	{
            		rm_num = section.room_connec.room_num;

               	// rm_num positions file pointer to the correct record in file
              		fseek ( roomPtr, ( rm_num - 1 ) * sizeof( ROOM_DATA ), SEEK_SET );
               	// reads record from file in room structure
         			fread ( &room, sizeof( ROOM_DATA ), 1, roomPtr );

             		// Writes to guest_history file
            		fseek( logger, ( NULL ) * sizeof( ADMISSION_DATA ), SEEK_SET );
               	fread( &section, sizeof ( ADMISSION_DATA ), 1, logger );
               	section.cancel = 2; // 2 = reservation was cancelled
               	section.charge = room.room_rate * .01; // cancellations subject to 1% charge on room cost
               	section.room_connec.room_rate = room.room_rate;  // needed for display in income_report function

               	// rm_num positions file pointer to the correct record in file
               	fseek( logger, ( NULL ) * sizeof( ADMISSION_DATA ), SEEK_SET );
               	// reads record from file in room structure
               	fwrite( &section, sizeof( ADMISSION_DATA ), 1, logger );
               	// end of guest_history writer

               	rm_num = section.room_connec.room_num;

               	// Updates room.txt
         			fseek ( roomPtr, ( rm_num - 1 ) * sizeof( ROOM_DATA ), SEEK_SET );
         			fread ( &room, sizeof( ROOM_DATA ), 1, roomPtr );
               	room.room_status = 10;
         			fseek ( roomPtr, ( rm_num - 1 ) * sizeof( ROOM_DATA ), SEEK_SET );
         			fwrite( &room, sizeof( ROOM_DATA ), 1, roomPtr );
               	// end of rooms.txt updater

               	// Erases reservation record by writing blank data
   					fseek( reserver, (res_num - 1) * sizeof( ADMISSION_DATA ), SEEK_SET );
      				fwrite( &res_remover, sizeof( ADMISSION_DATA ),1 ,reserver );

               	// update confirmation
         			textcolor(10); printf("\n"); cprintf("RESERVATION SUCCESSFULLY CANCELLED"); sleep(3);
               }
            }
            else
            {
            	if (confirm == 2)
               {
               	printf("\nReservation Cancellation process aborted");
               }
               else
               {
               	printf("\nOnly 1 or 2 maybe selected");
               }
               _getch(); // pauses the screen until the user enters any value
            }
            fclose(logger); // flcose closes guest_history.txt file
         }
      	fclose(reserver);  // flcose closes reservations.txt file
         fclose(roomPtr);   // flcose closes rooms.txt file
		}
   }
   if( system( "cls" ) != 0 ) system( "clear" ); // clears the console of all output before returning to main menu
}



/* ++++++++GUEST CHECK-IN FUNCTION++++++++ */
void checkin()
{
   int res_num = 0;  // reservation number
   int confirm;
	FILE *reserver;   // reservations.txt file pointer
   FILE *roomPtr;    // rooms.txt file pointer

   // fopen opens rooms.txt file; exits if cannot be opened
   if(( roomPtr=fopen("rooms.txt", "rb+")) == NULL)
   {
   	textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
   }
   else
   {  // fopen opens reservations.txt file; exits if cannot be opened
   	if((reserver=fopen("reservations.txt","rb+"))==NULL)
   	{
   		textcolor(12); cprintf("\nERROR!! RESERVATION FILE COULD NOT BE OPENED!"); sleep(3);
   	}
   	else
   	{
         printf("Welcome to the Check-In Section!");

			printf("\n\nPlease enter the reservation number: ");
			scanf("%d",&res_num);

      	fseek( reserver, ( res_num - 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
      	fread( &section, sizeof( ADMISSION_DATA ), 1, reserver );

         // checks to see if a reservation was made
      	if( section.reservation_num == 0 )
      	{
      		textcolor(12); cprintf("\nINVALID!! NO RESERVATION WAS MADE!"); sleep(3);
      	}
      	else
      	{  // displays reserver's details for confirmation purposes
      		printf("\n%d\tMr/Ms. %s %s\t Credit Card: %d", section.guest_num, section.first_name, section.last_name, section.credit_card);
            printf("\n\nConfirm Check-In? (1 for yes, 2 for no): ");
            scanf("%d", &confirm);

            if (confirm == 1)  // if the users selected yes
         	{
            	fseek( roomPtr, ( section.room_connec.room_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );
               fread( &room, sizeof( ROOM_DATA ), 1, roomPtr );

         		room.room_status = 12; // 12 = occupied

               fseek( roomPtr, ( section.room_connec.room_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );
               fwrite( &room, sizeof( ROOM_DATA ), 1, roomPtr);

               // confirmation message
               printf("\n\nMr/Ms. %s %s sucessfully checked-in", section.first_name, section.last_name);
               sleep(2);
            }
            else
            {
            	if (confirm == 2)  // if the users selected no
               {
               	printf("\nCheck-In process cancelled");
               	sleep(2);
               }
               else
               {
               	printf("\nOnly 1 or 2 maybe selected");
                  sleep(2);
               }
            }
      	}
       	fclose ( reserver ); // flcose closes reservations.txt file
   	}
      fclose ( roomPtr ); // flcose closes reservations.txt file
	}
}



/* +++++++GUEST CHECK-OUT FUNCTION+++++++++ */
void checkout()
{
	FILE *reserver;   // reservations.txt file pointer
   FILE *roomPtr;    // rooms.txt file pointer
   FILE *logger;     // guest_history file pointer
   int res_num;      // reservation number
   int confirm;
   int rm_num;       // room number

   // create ADMISSION_DATA with no information
   static ADMISSION_DATA booking_remover={NULL,NULL,"","","",0,999,0.00,1,0};

   // fopen opens the file; exits if file cannot be opened
   if(( roomPtr=fopen("rooms.txt", "rb+")) == NULL )
   {
   	textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
   }
   else
   {  // fopen opens the file; exits if file cannot be opened
   	if((reserver=fopen("reservations.txt","rb+"))==NULL)
   	{
   		textcolor(12); cprintf("\nERROR!! RESRVATION FILE COULD NOT BE OPENED!"); sleep(3);
   	}
     	else
      {
         printf("Welcome to the Check-Out Section!");

      	printf("\n\nPlease enter the reservation number:");
			scanf("%d",&res_num);
         // positions file pointer to the correct record in file
         fseek( reserver, ( res_num - 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
         // reads record from file in section structure
      	fread( &section, sizeof( ADMISSION_DATA ), 1, reserver );

         // checks to see if reservation was made; # must be (1 - 50)
         if( section.reservation_num == 0 )
      	{
      		textcolor(12); cprintf("\nINVALID!! NO RESERVATION WAS MADE/GUEST NOT CHECKED-IN!"); sleep(3);
      	}
         else
         {  // fopen opens/creates the file for appending; exits if file cannot be opened/created
         	if((logger = fopen("guest_history.txt", "ab")) == NULL )
            {
            	cprintf("\nERROR!! HISTORY FILE COULD NOT BE CREATED!"); sleep(3);
            }
            else
            {
            	// displays guest details for confirmation purposes
         		printf("\n%d\t%s\t%s\t%d", section.reservation_num, section.first_name, section.last_name, section.credit_card);
            	printf("\n\nConfirm Check-out? (1 for yes, 2 for no): ");
            	scanf("%d", &confirm);

            	if (confirm == 1)
         		{
            		rm_num = section.room_connec.room_num;

                  // rm_num positions file pointer to the correct record in file
                  fseek ( roomPtr, ( rm_num - 1 ) * sizeof( ROOM_DATA ), SEEK_SET );
                  // reads record from file in room structure
         			fread ( &room, sizeof( ROOM_DATA ), 1, roomPtr );

                  // Writes to guest_history file
            		fseek( logger, ( NULL ) * sizeof( ADMISSION_DATA ), SEEK_SET );  // &&&&&&&& END
               	fread( &section, sizeof ( ADMISSION_DATA ), 1, logger );
               	section.cancel = 1; // 1 = reservation was NOT cancelled
               	section.charge = room.room_rate * section.length_stay;
                  section.room_connec.room_rate = room.room_rate;
               	fseek( logger, ( NULL ) * sizeof( ADMISSION_DATA ), SEEK_SET );  // &&&&&&&&  END
               	fwrite( &section, sizeof( ADMISSION_DATA ), 1, logger );
               	// end of guest_history writer

                  // Guest Invoice/Bill
                 	if( system( "cls" ) != 0 ) system( "clear" );
                  printf("\n*******************SSI INVOICE*************************\n\n");
                  printf("Guest Name\t: %s %s. %s\n", section.first_name, section.MI, section.last_name);
                  printf("Room Number\t: %d\n", section.room_connec.room_num);
                  printf("Room Type\t: ");
               	(section.room_connec.room_num == 1?printf("Smoking\n"):printf("Non-Smoking\n"));
                  printf("Amount\t\t: JMD $ %.2f\t  US $ %.2f\n", section.room_connec.room_rate, (section.room_connec.room_rate / 72));
                  printf("\n*******************************************************\n");
                  _getch();
                  // End of Invoice

                  rm_num = section.room_connec.room_num;

                  // Erases reservation record by writing blank data
            		fseek( reserver, ( res_num - 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
               	fwrite( &booking_remover, sizeof( ADMISSION_DATA ),1 ,reserver );

               	// Updates room.txt
            		fseek( roomPtr, ( rm_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );
               	fread( &room, sizeof( ROOM_DATA ), 1, roomPtr );
         			room.room_status = 10;
               	fseek( roomPtr, ( rm_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );
               	fwrite( &room, sizeof( ROOM_DATA ), 1, roomPtr);

                  // confirmation message printed
                  textcolor(10); printf("\n"); cprintf("GUEST SUCCESSFULLY CHECKED-OUT"); sleep(3);
            	}
            	else
            	{
            		if (confirm == 2)
               	{
               		printf("\nCheck-out process cancelled");
               	}
               	else
               	{
               		printf("\nOnly 1 or 2 maybe selected");
               	}
               	_getch();
            	}
            }
         }
      }
      fclose( reserver ); // fclose closes reservations.txt file
   }
   fclose( roomPtr );     // fclose closes rooms.txt file
}



/* +++++++INCOME REPORT FUNCTION++++++++ */
void incomereport()
{
	void insertion_sort(); // local function for sorting guests of the guest_history.txt alphabetically
	FILE *logger;          // guest_history.txt file pointer
   float total_cancel = 0.00;   // total income from cancellations
   float total_chk_out = 0.00;  // total income from checked-out guests
   float grand_total;           // TOTAL INCOME (total_cancel + total_chk_out)

   // fopen opens file, attempts to create one if cannot be opened
   if(( logger = fopen("guest_history.txt", "rb")) == NULL )
   {
   	textcolor(12); cprintf("\nERROR!! HISTORY FILE COULD NOT BE OPENED!"); sleep(3);
   }
   else
   {
   	insertion_sort();  // call to function for alphabetical sorting

      printf( "---------------------------CHECKED-OUT GUESTS-------------------------------\n" );

      // reads all the records of the file
   	while ( fread( &section, sizeof (ADMISSION_DATA), 1, logger ) == 1 )
      {
         if( section.cancel == 1) // checks for cancellations
         {
         	// formatted output for report
            printf("\nFirst Name:\t%s\n", section.first_name);
            printf("Last Name:\t%s\n", section.last_name);
            printf("Middle I.:\t%s\t\t", section.MI);
            printf("Room Rate:\t%.2f\t", section.room_connec.room_rate);
            printf("   Duration:\t%d\n", section.length_stay);
            printf("Guest Num:\t%d\t\t", section.guest_num);
            printf("Charge:\t\t%.2f\n", section.charge);

            total_chk_out += section.charge; // calculates total check-out charges collected
         }
      }

      rewind( logger ); // sets pointer to beginning of file

      printf( "\n\n\n--------------------------CANCELLED RESERVATION------------------------------\n" );

      // reads all the records of the file
   	while ( fread( &section, sizeof (ADMISSION_DATA), 1, logger ) == 1 )
      {
         if( section.cancel == 2) // checks for checked-out guests
         {
         	// formatted output for report
            printf("\nFirst Name:\t%s\n", section.first_name);
            printf("Last Name:\t%s\n", section.last_name);
            printf("Middle I.:\t%s\t\t", section.MI);
            printf("Room Rate:\t%.2f\t", section.room_connec.room_rate);
            printf("   Duration:\t%d\n", section.length_stay);
            printf("Guest Num:\t%d\t\t", section.guest_num);
            printf("Charge:\t\t%.2f\n", section.charge);

            total_cancel += section.charge; // calculates total reservation cancellation charges collected
         }
      }

      grand_total = total_chk_out + total_cancel; // calculates grand total

      printf("\n\n\nTOTAL CANCELLATIONS:\t$ %.2f\nINCOME:\t\t\t$ %.2f\nGRAND TOTAL:\t\t$ %.2f", total_cancel, total_chk_out, grand_total);
      _getch();
	}
   fclose( logger ); // fclose closes guest_history.txt file
}



/* +++++++++INSERTION SORT FUNCTION +++++++++++ */
void insertion_sort()
{
	FILE *guest_Ptr; // guest_history.txt file pointer
   int size=0;      // represents the total # of records in the file
   int outer_run;
   int inner_run;
   int grand_run=0; // ensures that all the records are sorted

   // blank structure which stores the smallest value
   ADMISSION_DATA small = {NULL,NULL,"","","",0,999,0.00,1,0};

   // fopen opens the guest_history.txt file, exits function is file cannot be opened
   if( (guest_Ptr = fopen("guest_history.txt", "rb+")) == NULL )
   {
   	textcolor(12); cprintf("\nERROR!! HISTORY FILE COULD NOT BE OPENED!"); sleep(3);
   }
   else
   {
      // counts the number of guest records in the file
      while ( fread( &section, sizeof (ADMISSION_DATA), 1, guest_Ptr ) == 1 )
      {
      	size++;
      }
      // sets pointer to start of file
      rewind( guest_Ptr );

      grand_run -= size;

      // sort loop equal to the number of records to ensure 100% file sort
      while (grand_run <= 0)
      {  // START OF SORTING ALGORITHM
      	for(outer_run = 1; outer_run < size; outer_run++)
      	{
      		fseek( guest_Ptr, ( outer_run ) * sizeof( ADMISSION_DATA ), SEEK_SET );
         	fread( &section, sizeof( ADMISSION_DATA ), 1, guest_Ptr );
         	small = section;

         	rewind ( guest_Ptr );

         	inner_run = outer_run - 1;

         	fseek( guest_Ptr, ( inner_run ) * sizeof( ADMISSION_DATA ), SEEK_SET );
         	fread( &section, sizeof( ADMISSION_DATA ), 1, guest_Ptr );
         	rewind ( guest_Ptr );

         	for(; inner_run >= 0 && (strcmp( small.first_name, section.first_name) <= 0 ); inner_run--)
         	{
         		fseek( guest_Ptr, ( inner_run ) * sizeof( ADMISSION_DATA ), SEEK_SET );
            	fread( &section, sizeof( ADMISSION_DATA ), 1, guest_Ptr );

            	fseek( guest_Ptr, ( inner_run + 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
            	fwrite( &section, sizeof( ADMISSION_DATA ), 1, guest_Ptr );
         	}

         	fseek( guest_Ptr, ( inner_run + 1 ) * sizeof( ADMISSION_DATA ), SEEK_SET );
         	fwrite( &small, sizeof( ADMISSION_DATA ), 1, guest_Ptr );
      	}
         // END OF SORTING ALGORITHM
      	grand_run++; // grant_run incremented by one until zero is reached
      }
   }
   fclose( guest_Ptr ); // flcose closes the guest_history file
} // Control is returned to the report function



/* ++++++++ROOM AVAILABILITY REPORT+++++++++ */
void room_available_report()
{
	FILE *roomPtr; // rooms.txt file pointer

   // fopen opens the rooms.txt file; exits function if file cannot be opened
   if(( roomPtr = fopen( "rooms.txt", "rb")) == NULL)
   {
   	textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
   }
   else
   {
   	textcolor(14);
   	cprintf("----------AVALIABLE SMOKING ROOMS---------------");
   	textcolor(15);
      printf("\n");
      cprintf("R_NUM        R_TYPE     R_RATE       R_STATUS");

      // reads through all records in the file
   	while ( (fread( &room, sizeof (ROOM_DATA), 1, roomPtr)) == 1 )
      {
         // room data must be set, type must be smoking, and status set to available
         if( room.room_num != 0 && room.room_type == 1 && room.room_status == 10)
         {
         	printf( "\n%d\t\t%d\t%.2f\t\t%d", room.room_num, room.room_type, room.room_rate, room.room_status );
         }
      }

      rewind( roomPtr ); // sets pointer to beginning of file

      printf("\n\n");
      textcolor(14);
      cprintf("----------AVALIABLE NON-SMOKING ROOMS-----------");
      textcolor(15);
      printf("\n");
      cprintf("R_NUM        R_TYPE     R_RATE       R_STATUS");

      // reads through all records in the file
      while ( (fread( &room, sizeof (ROOM_DATA), 1, roomPtr)) == 1 )
      {
         // room data must be set, type must be non-smoking, and status set to available
         if( room.room_num != 0 && room.room_type == 2 && room.room_status == 10)
         {
         	printf( "\n%d\t\t%d\t%.2f\t\t%d", room.room_num, room.room_type, room.room_rate, room.room_status );
         }
      }
      getchar(); // waits for user to enter character from the keyboard
      fclose ( roomPtr ); // fclose closes rooms.txt file
   }
   if( system( "cls" ) != 0 ) system( "clear" ); // clears the console
}



/* +++++++RESERVATION REPORT+++++++ */
void reservation_report()
{
	FILE *reserver;  // reservations.txt file pointer
   FILE *roomPtr;   // rooms.txt file pointer

   // fopen opens file; exits function is file cannot be opened
	if((reserver = fopen( "reservations.txt", "rb")) == NULL)
   {
   	textcolor(12); cprintf("\nERROR!! RESERVATION FILE COULD NOT BE OPENED!"); sleep(3);
   }
   else
   {  // fopen opens room file; exits function is file cannot be opened
   	if (( roomPtr = fopen( "rooms.txt", "rb")) == NULL)
      {
      	textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
      }
      else
      {  // reads through all records in the file
   		while (!feof( reserver ))
   		{  // reads reservation record into section
   			fread( &section, sizeof ( ADMISSION_DATA ), 1, reserver);
            // positions pointer at room cooresponding with reservation
            fseek( roomPtr, ( section.room_connec.room_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );
            // reads room data in room
            fread( &room, sizeof ( ROOM_DATA ), 1, roomPtr);

            // checks if a reservation was made and the room is reserved
      		if( section.reservation_num != 0 && room.room_status == 9 )
      		{
            	// formatted output for report
            	printf( "---------------RESERVATION DATA---------------\n" );
            	printf("\nReser. Num:\t%d\t\t", section.reservation_num);
            	printf("Credit Card\t%d\n", section.credit_card);
            	printf("Guest Num:\t%d\t\t", section.guest_num);
            	printf("Contact #:\t%d\n", section.telephone);
            	printf("First Name:\t%s\t\t", section.first_name);
            	printf("Charge:\t\t%.2f\n", section.charge);
            	printf("Middle I.:\t%s\t\t", section.MI);
            	printf("Duration:\t%d\n", section.length_stay);
            	printf("Last Name:\t%s\t\t", section.last_name);
            	printf("Cancel:\t\t%d\n\n", section.charge);
              	printf( "---------------ROOM DATA----------------------\n" );
            	printf("\nRoom Num:\t%d\t\t", section.room_connec.room_num);
            	printf("Room Type:\t");
               (section.room_connec.room_type == 1? printf("SMOKING\n\n\n"):printf("NON-SMOKING\n\n\n"));
      		}
   		}
      	getchar();       // waits for user to enter character from the keyboard
      }
      fclose ( roomPtr ); // fclose closes rooms.txt
   }
   fclose( reserver );    // fclose closes reservations.txt
   if( system( "cls" ) != 0 ) system( "clear" );        // clears display console
}



/* ++++++ROOM INFORMATION SUB-MENU FUNCTION++++++++ */
void room_info_menu()
{
	FILE *roomPtr;   // roomPtr = rooms.txt file pointer
   int count = 1;
	int choice;   	  // user's choice

   printf("Welcome to the room sub-menu!\n\n");
   printf("1\tCreates/reset room info.\n2\tModify room info\n3\tView rooms\n\nEnter your selection now: ");
   scanf("%d", &choice);

   switch (choice)
   {
   	case 1:
   	if((roomPtr = fopen("rooms.txt", "wb")) == NULL)
   	{
      	textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE CREATED!"); sleep(3);
   	}
   	else
   	{
   		for(; count <= 50; count++)  // outputs 50 blank records to file
      	{
      		fwrite(&room, sizeof( ROOM_DATA ), 1, roomPtr );
      	}
         textcolor(10); printf("\n\n"); cprintf("ROOM FILE SUCCESSFULLY CREATED"); sleep(3);
   	}
      fclose( roomPtr );   // room file closed here
   	break;

   	case 2:
      // fopen opens the file; exits if file cannot be opened
   	if((roomPtr = fopen("rooms.txt", "rb+")) == NULL)
   	{
   		textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
   	}
   	else
   	{
   		printf( "\nEnter Room Number ( 1 to 50, -1 to end input): " );
      	scanf("%d", &room.room_num);

      	while( room.room_num != -1 && room.room_num > 0 && room.room_num < 51 )
      	{
      		printf("\nEnter Room Type: ");
         	scanf("%d", &room.room_type);

         	switch (room.room_type)    //1- smoking 2- non-smoking
         	{
         		case 1:
            	room.room_rate = 4000.00; // smoking rate is $4000
            	break;

            	case 2:
            	room.room_rate = 3000.00;  // non-smoking rate is $3000
            	break;

            	default:
            	textcolor(12); printf("\n"); cprintf("ONLY 1 AND 2 ARE VALID OPTIONS"); printf("\n");
            	break;
         	}

            // ensures that nothing is done if the user selects an invalid type
            if ( room.room_type == 1 || room.room_type == 2)
            {
         		room.room_status = 10;  // 10 = vacant

            	// sets file pointer at room specified by user
         		fseek( roomPtr, (room.room_num -1) * sizeof ( ROOM_DATA ), SEEK_SET );
            	// updates room file
         		fwrite( &room, sizeof ( ROOM_DATA ), 1, roomPtr );
            	// user prompt
         		printf( "\nEnter Room Number ( 1 to 50, -1 to end input): " );
      			scanf("%d", &room.room_num);
            }
      	}

         // checks if user entered invalid option
         if( room.room_num < -1 || room.room_num > 50 || room.room_num == 0 )
         {
         	textcolor(12); printf("\n"); cprintf("ROOM NUMBER MUST BE GREATER THAN 0 AND LESS THAN 51"); sleep(5);
         }
      }
      fclose( roomPtr );  // room file closed here
      break;

   	case 3:
   	if(( roomPtr = fopen( "rooms.txt", "rb")) == NULL)
   	{
   		textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
   	}
   	else
   	{
         printf("\n"); textcolor(15); cprintf("R_#     RM_TYPE         RM_RATE         RM_STAT"); printf("\n");

        // reads all records from the file until the end of the file (eof)
   		while ( !feof(roomPtr) )
         {
            fread( &room, sizeof( ROOM_DATA ), 1, roomPtr );

         	if( room.room_num != 0) // checks to see if user has eentered details about the room
            {
            	printf( "%d", room.room_num );

               if( room.room_type == 1 )
               	printf("\tSMOKING");

               if( room.room_type == 2 )
               	printf("\tNON-SMO");

               printf("\t\t%.2f\t\t", room.room_rate);

               if( room.room_status == 9 )
               	printf("RESERVED\n");

               if( room.room_status == 10 )
               	printf("VACANT\n");

               if( room.room_status == 12 )
               	printf("OCCUPIED\n");
            }
         }
      	_getch();
   	}
      fclose( roomPtr );
   	break;

   	default:
   	textcolor(12); cprintf("\nONLY 1, 2, 3 ARE VALID OPTIONS"); sleep(3);
   	break;
   }
   if( system( "cls" ) != 0 ) system( "clear" ); // clears the console of all output
}



/* ++++++EXTRA FUNCTION FOR SEEING ALL RESERVATIONS AND BOOKED GUESTS++++++ */
void all_guests_report()
{
	FILE *reserver; // reservations.txt file pointer
   FILE *roomPtr;  // rooms.txt file pointer

   // fopen opens the reservations.txt file, exits function if cannot be opened
   if(( reserver = fopen( "reservations.txt", "rb")) == NULL)
   {
   	textcolor(12); cprintf("\nERROR!! RESERVATION FILE COULD NOT BE OPENED!"); sleep(3);
   }
   else
   {  // fopen opens the rooms.txt file, exits function if cannot be opened
   	if (( roomPtr = fopen( "rooms.txt", "rb")) == NULL)
   	{
   		textcolor(12); cprintf("\nERROR!! ROOM FILE COULD NOT BE OPENED!"); sleep(3);
   	}
   	else
   	{
      	printf( "+++++++++++++++++++CHECKED-IN GUEST DATA++++++++++++++++++\n\n\n" );

      	 // reads all records in the file
      	while (!feof( reserver ) )
      	{
      		fread( &section, sizeof (ADMISSION_DATA), 1, reserver);

            fseek( roomPtr, ( section.room_connec.room_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );

            fread( &room, sizeof ( ROOM_DATA ), 1, roomPtr);

            // only rooms whose data is set and checked-in
         	if( section.reservation_num != 0 && room.room_status == 12)
         	{
            	// formatted output for extra function
              	printf( "------------------------GUEST DATA------------------------\n" );
            	printf("\nReser. Num:\t%d\t\t", section.reservation_num);
            	printf("Credit Card\t%d\n", section.credit_card);
            	printf("Guest Num:\t%d\t\t", section.guest_num);
            	printf("Contact #:\t%d\n", section.telephone);
            	printf("First Name:\t%s\t\t", section.first_name);
            	printf("Charge:\t\t%.2f\n", section.charge);
            	printf("Middle I.:\t%s\t\t", section.MI);
            	printf("Duration:\t%d\n", section.length_stay);
            	printf("Last Name:\t%s\t\t", section.last_name);
            	printf("Cancel:\t\t%d\n\n", section.charge);
            	printf( "------------------------ROOM DATA--------------------------\n" );
            	printf("\nRoom Num:"); printf("\t%d\t\t", section.room_connec.room_num);
            	printf("Room Type:\t");
               (section.room_connec.room_type == 1? printf("SMOKING\n\n\n"):printf("NON-SMOKING\n\n\n"));
         	}
      	}

         rewind( reserver ); // sets file pointer to beginning of file

         printf( "\n\n\n\n\n+++++++++++++++++++RESERVED GUEST DATA++++++++++++++++++++++\n\n\n" );

         // only rooms whose data is set and reserved
         while (!feof( reserver ) )
      	{
      		fread( &section, sizeof (ADMISSION_DATA), 1, reserver);

            fseek( roomPtr, ( section.room_connec.room_num - 1 ) * sizeof ( ROOM_DATA ), SEEK_SET );

            fread( &room, sizeof ( ROOM_DATA ), 1, roomPtr);

            if( section.reservation_num != 0 && room.room_status == 9)
         	{
            	// formatted output for extra function
              	printf( "------------------------GUEST DATA--------------------------\n" );
            	printf("\nReser. Num:\t%d\t\t", section.reservation_num);
            	printf("Credit Card\t%d\n", section.credit_card);
            	printf("Guest Num:\t%d\t\t", section.guest_num);
            	printf("Contact #:\t%d\n", section.telephone);
            	printf("First Name:\t%s\t\t", section.first_name);
            	printf("Charge:\t\t%.2f\n", section.charge);
            	printf("Middle I.:\t%s\t\t", section.MI);
            	printf("Duration:\t%d\n", section.length_stay);
            	printf("Last Name:\t%s\t\t", section.last_name);
            	printf("Cancel:\t\t%d\n\n", section.charge);
            	printf( "------------------------ROOM DATA--------------------------\n" );
            	printf("\nRoom Num:"); printf("\t%d\t\t", section.room_connec.room_num);
            	printf("Room Type:\t");
               (section.room_connec.room_type == 1? printf("SMOKING\n\n\n"):printf("NON-SMOKING\n\n\n"));
         	}
         }
         getchar();
      }
      fclose( roomPtr ); // fclose closes rooms.txt
	}
   fclose( reserver );   // fclose closes reservations.txt
}

welp, i just tried to compile your C code, and got a flood of compiler errors.

god forbid anyone try and run your code on a non-Windows environment.

for this reason you should stay away from CONIO.H and DOS.H...

but i imagine your entire class uses nothing but windows, and your instructor doesn't care if he teaches you programming without regard to the ugly consequences of using Non-ANSI C

anyhow, im on my way upstairs now, so maybe I'll peek at it on my vista laptop.

okay, WTF is this? fseek( logger, ( NULL ) * sizeof( ADMISSION_DATA ), SEEK_SET ); NULL * sizeof(something) ?? zero times anything is still zero. if you just want the beginning of the file, why are you using fseek?

but a larger issue: NULL is a pointer. not an int. you cant multitply a pointer and an int. at least not on most compilers. Borland maybe you can get away with it, but not GCC. and probably not MSVC either.

Im still getting a bazillion compiler warnings and errors when i try and compile it on MSVC.

i changed the #include <dos.h> to <windows.h>, and changed your sleep() calls to Sleep(). that got rid of some of them, but brought in new ones to replace it.

did this compile for you even, on Borland?

and whether it did or didn't, you should really think about getting rid of Borland compiler, in favor of GCC or MSVC. borland was in the trash bin 10 years ago.

This article has been dead for over six months. Start a new discussion instead.