Searching and displaying problem in my program

This is a discussion on Searching and displaying problem in my program within the C++ Programming forums, part of the General Programming Boards category; can anybody plz help me? here is the file im talking about, its my program about billing system.. http://www.sendspace.com/file/8lofqe i ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    3

    Searching and displaying problem in my program

    can anybody plz help me?

    here is the file im talking about, its my program about billing system..
    http://www.sendspace.com/file/8lofqe

    i have a problem in the searching and displaying part...

    ive positioned everything to the place that i wanted however when i compiled it...it doesnt give me the result just like i expected...

    so is there any solution to this i really need your help

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    3

    the code

    Code:
    /***Hotel Billing System - Ak Muhammad Adib****/
    /*************C++ Project 2007*****************/
    
    /*********Tempat mendeclare Header files**********/
    
    
    #include <stdio.h>
    #include <iostream.h>
    #include <fstream.h>
    #include <ctype.h>
    #include <dos.h>
    #include <conio.h>
    #include <iomanip.h>
    #include <stdlib.h>
    #include <string.h>
    #include <graphics.h>
    #include <math.h>
    #include <time.h>
    
    
    /*********Tempat mendefine macro*********/
    
    
    #define NUM 7
    #define PH 11
    #define MIN 30
    
    
    
    /*********Tempat mendeclare function*********/
    
    
    /*********************************************MENU PROTOTYPE************************************************/
    
    /*MAIN MENU*/
    
    
    void add_menu(void);
    void search_menu(void);
    void display_menu(void);
    void print_menu(void);
    
    /*ADD SUB-MENU*/
    
    int add_booking(void);	/*Ask user to input booking information*/
    int add_check(void);	/*Ask user to input check-in information*/
    
    /*SEARCH SUB-MENU*/
    
    int searchbook();	/*Search for booking record*/
    int searchcheck();	/*Search for check-in record*/
    
    /*DISPLAY SUB-MENU*/
    
    int dis_custrec();	/*Display customer's receipt*/
    int dis_bookrep();	/*Display booking report*/
    int dis_checkrep();	/*Display customer report by room type*/
    
    /*PRINT SUB-MENU*/
    
    void print_custrec();	/*Print customer's receipt*/
    void print_bookrep();	/*Print booking report*/
    void print_custrep();	/*Print customer report by room type*/
    
    
    
    
    /*********Tempat mendeclare structure*********/
    
    
    struct customer
    {
    	char bookingID[NUM];
    	char name[MIN];
    	char dob[MIN];
    	char ic_no[NUM];
    	char tel_no[PH];
    	char date_arr[MIN];
    	char date_dep[MIN];
    	char room_type[MIN];
    	char nationality[MIN];
    	int room_no;
    	int duration;
    	int payment_type;
    	char pay_type[MIN];
    	float price;
    	float total;
    }rec;
    
    
    /****************************************************START OF HOTEL BILLING SYSTEM*******************************************************/
    
    
    
    /***************************Main Menu*****************************/
    
    main()
    {
     int c;
    
     textcolor(LIGHTGRAY);
     textbackground(BLACK);
    
     do
     {
    	clrscr();
    	
    	gotoxy(30,2);
    	cout<<"*****************************";
    	gotoxy(30,3);
    	cout<<"<< C3 Hotel Billing System >>";
    	gotoxy(30,4);
    	cout<<"*****************************";
    
    
    	gotoxy(33,8);
    	printf("[1] ADD MENU");
    	gotoxy(33,10);
    	printf("[2] SEARCH MENU");
    	gotoxy(33,12);
    	printf("[3] DISPLAY MENU");
    	gotoxy(33,14);
    	printf("[4] PRINT MENU");
    	gotoxy(33,16);
    	printf("[5] EXIT");
    	gotoxy(24,22);
    	textcolor(LIGHTGRAY);
    	cprintf("PLEASE SELECT A CHOICE [1-5]: ");
    
    	c = (getche());
    
    		switch (c)      //This 'SWITCH' structure will ask the user for input from [1] to [5] and will display error on Invalid Entry.
    			{
    				case '1':  add_menu();	
    					   break;
    				
    
    				case '2':  search_menu();
    					   break;   
    
    
    				case '3':  display_menu();
    					   break;   
    				
    
    				case '4':  	
    					   break;   
    
    
    				case '5':  gotoxy(30,24);
    					   cout<<"<<<<--THANK YOU-->>>>"<<endl;
    	   				   cout<<"\n\t\t\t****Done by : Adib Kamarudin****"<<endl;
    	   				   cout<<"\n\t\t\t*******PROGRAM  TERMINATED******";
    					   getch();exit(0);
    
    
    
    				default:
    				sound(500);delay(200);nosound(); 	//sound turns the PC speaker on at the specified frequency, nosound turns the PC speaker off.
    				gotoxy(26,24);
    				puts("<<--ENTER FROM 1-5 PLEASE-->>");	//This message will only print on INVALID ENTRY and Will ask again for input.
    				getch();
    			}
    
    }
    while(c != '5'); 	//This 'WHILE' loop will continue till the Exit option [5] is entered.
    
    return 0;
    }
    
    /*******************ADD Submenu(option 1 of main menu)********************/
    void add_menu(void)
    {
     int c;
     
      do 
      {
      textbackground(BLACK);
      textcolor(LIGHTGRAY);
    
      clrscr();
    
      gotoxy(30,2);
      cout<<"*****************************";
      gotoxy(30,3);
      cout<<"<< C3 Hotel Billing System >>";
      gotoxy(30,4);
      cout<<"*****************************";
      
      gotoxy(33,7);
      cputs("1.Add Booking Record.");
      gotoxy(33,9);
      cputs("2.Add Check-in Record.");
      gotoxy(33,11);
      cputs("3.Back to Main menu.");
      gotoxy(33,15);
      textcolor(LIGHTGRAY);
      cprintf("ENTER CHOICE [1-3]: ");
    
      fflush(stdin);
      
      c = (getche());
    
      switch(c)
      {
       case '1': add_booking();
    	     break;
    
       case '2': add_check();
    	     break;
    
       case '3': break;
    
       default: sound(500);delay(200);nosound(); 	//sound turns the PC speaker on at the specified frequency, nosound turns the PC speaker off.
    	    gotoxy(26,24);
    	    puts("<<--ENTER FROM 1-3 PLEASE-->>");	//This message will only print on INVALID ENTRY and Will ask again for input.
                getch();
      }
     }
     while(c != '3');
    }
    
    /*****************Add Booking Item(option 1 of order menu)*************************/
    int add_booking(void)
    {
     char f_rest[81],name[30],dob[15],ic_no[15],tel_no[15], response = 'Y', duplicate = 'N';
     char bookingID[9],file_booking_id[9],date_arr[15],date_dep[15],room_type[15],nationality[15],payment_type[20];
     int no_per,room_no,duration;
     float price, total;
    
     FILE *fp;
     response='Y';
     while (response=='Y')
     {
      clrscr();
    
      /*Initialization*/
      duplicate='N';
    
      /*print header*/
      gotoxy(25,3);
      cputs("Add New Booking Data To File.");
      gotoxy(25,4);
      cputs("-----------------------------");
    
      /*get booking ID*/
      gotoxy(25,6);
      cputs("Booking ID.[4 digit only]:");
      do
      {
       gotoxy(52,6);clreol();gets(bookingID);
       if(strlen(bookingID)!=4)
         {
          gotoxy(23,21);cputs("\a");textcolor(RED+BLINK);
          cputs("Invalid input..Booking ID must be 4 digit");
          getche();textcolor(BLUE);gotoxy(23,21);clreol();
         }
       }
       while(strlen(bookingID)!=4);
       /*check for duplication*/
       fp=fopen("booking.txt","a+");
       rewind(fp);
       fp=fopen("booking.txt","r");
       while(!feof(fp))
       {
        /*get booking ID from file*/
        fgets(file_booking_id,5,fp);
        fgets(f_rest,66,fp);
    
        /*compare both booking ID*/
        if(strcmp(file_booking_id,bookingID)==0)
        {
         gotoxy(28,21);cputs("\a");textcolor(RED+BLINK);
         cputs("Data Existed In File!!!");
         getche();textcolor(BLUE);gotoxy(28,21);clreol();
         duplicate='y';
         break;
        }
       }
       /*get data from user*/
       if(duplicate=='N')
       {
        gotoxy(25,8);cputs("Name:");
        gotoxy(32,8);gets(name);
        gotoxy(25,9);fflush(stdin);cputs("Date of birth(dd/mm/yyyy):");
        gotoxy(53,9);gets(dob);
        gotoxy(25,10);cputs("Nationality:");
        gotoxy(39,10);gets(nationality);
        gotoxy(25,11);cputs("Telephone Number: +");
        gotoxy(44,11);gets(tel_no);
        fflush(stdin);
        gotoxy(25,12);cputs("Date of arrival(dd/mm/yyyy):");
        gotoxy(55,12);gets(date_arr);
        gotoxy(25,13);cputs("Date of departure(dd/mm/yyyy):");
        gotoxy(57,13);gets(date_dep);
        gotoxy(25,14);cputs("Room Number(1-300):");
        gotoxy(46,14);clreol();cin>>room_no;
        while((room_no < 1) || (room_no > 300))
        {
        gotoxy(25,21);cputs("\a");textcolor(RED+BLINK);
        cputs("Please reenter room number\n");
        getche();textcolor(BLUE);gotoxy(28,21);clreol();
        gotoxy(38,14);cin>>room_no;
        }
        gotoxy(25,15);cputs("Room Type:");
        if (room_no >= 1 && room_no < 101)
        {
        gotoxy(36,15);cout<<"Single"<<room_type;
        }
    	else
    	if (room_no > 100 && room_no < 201)
    	{
    	gotoxy(36,15);cout<<"Twin"<<room_type;
    	}
    		else if
    		(room_no > 200 && room_no < 301)
    		{
    		gotoxy(36,15);cout<<"Presidential"<<room_type;
    		}
    
        gotoxy(25,16);cputs("Duration:");
        gotoxy(36,16);clreol();cin>>duration;
    
        gotoxy(25,17);cputs("Room Price:");
        gotoxy(37,17);cout<<"$";
    
        if (room_no >= 1 && room_no < 101)
        {
        price = 100;
        gotoxy(38,17);cout<<price;
        }
    	else
    	if (room_no > 100 && room_no < 201)
    	{
    	price = 150;
    	gotoxy(38,17);cout<<price;
    	}
    		else if
    		(room_no >200 && room_no < 301)
    		{
    		price = 200;
    		gotoxy(38,17);cout<<price;
    		}
    
    
        fflush(stdin);
    
        /*write to file*/
        fp=fopen("booking.txt","a+");
        fprintf(fp,"%s",bookingID);
        fprintf(fp,"%s",name);
        fprintf(fp,"%s",dob);
        fprintf(fp,"%s",nationality);
        fprintf(fp,"%s",tel_no);
        fprintf(fp,"%s",date_arr);
        fprintf(fp,"%s",date_dep);
        fprintf(fp,"%s",room_type);
        fprintf(fp,"%3d",room_no);
        fprintf(fp,"%2d",duration);
        fprintf(fp,"%4.2f",price);
        fprintf(fp,"\n");
        fclose(fp);
       }
       /*get response from user*/
       gotoxy(25,35);clreol();
       cputs("Add another[Y/N]:");
       response=toupper(getche());
       fflush(stdin);
       fclose(fp);
       }
       return 0;
      }
    
    /********************************CHECK IN MENU**************************************************/
    
    int add_check(void)
    {
     char f_rest[81], reply, dupli;
     char file_ic_no[7];
    
     FILE *fp;
     reply='Y';
     while (reply=='Y')
     {
      clrscr();
    
      /*Initialization*/
      dupli='N';
    
      /*print header*/
      gotoxy(25,3);
      cputs("Add New Check-in Data To File.");
      gotoxy(25,4);
      cputs("-----------------------------");
    
      /*get IC Number*/
      gotoxy(25,6);
      cputs("IC Number[6 digit only]:");
      do
      {
       gotoxy(52,6);clreol();gets(rec.ic_no);
       if(strlen(rec.ic_no)!=6)
         {
          gotoxy(23,21);cputs("\a");textcolor(RED+BLINK);
          cputs("Invalid input..IC Number must be 6 digit");
          getche();textcolor(BLUE);gotoxy(23,21);clreol();
         }
       }
       while(strlen(rec.ic_no)!=6);
       /*check for duplication*/
       fp=fopen("checkin.txt","ab");
       rewind(fp);
       fp=fopen("checkin.txt","r");
       while(!feof(fp))
       {
        /*get ic number from file*/
        fgets(file_ic_no,7,fp);
        fgets(f_rest,66,fp);
    
        /*compare both ic number*/
        if(strcmp(file_ic_no,rec.ic_no)==0)
        {
         gotoxy(28,21);cputs("\a");textcolor(RED+BLINK);
         cputs("Data Existed In File!!!");
         getche();textcolor(BLUE);gotoxy(28,21);clreol();
         dupli='y';
         break;
        }
       }
       /*get data from user*/
       if(dupli=='N')
       {
        gotoxy(25,8);cputs("Name:");
        gotoxy(32,8);gets(rec.name);
        gotoxy(25,9);fflush(stdin);cputs("Date of birth(dd/mm/yyyy):");
        gotoxy(53,9);gets(rec.dob);
        gotoxy(25,10);cputs("Nationality:");
        gotoxy(39,10);gets(rec.nationality);
        gotoxy(25,11);cputs("Telephone Number: +");
        gotoxy(44,11);gets(rec.tel_no);
        fflush(stdin);
        gotoxy(25,12);cputs("Date of arrival(dd/mm/yyyy):");
        gotoxy(55,12);gets(rec.date_arr);
        gotoxy(25,13);cputs("Date of departure(dd/mm/yyyy):");
        gotoxy(57,13);gets(rec.date_dep);
        gotoxy(25,14);cputs("Room Number(1-300):");
        gotoxy(46,14);clreol();cin>>rec.room_no;
        while((rec.room_no < 1) || (rec.room_no > 300))
        {
        gotoxy(28,21);cputs("\a");textcolor(RED+BLINK);
        cputs("Please reenter room number\n");
        getche();textcolor(BLUE);gotoxy(28,21);clreol();
        gotoxy(38,14);cin>>rec.room_no;
        }
    
        gotoxy(25,15);cputs("Room Type:");
        if (rec.room_no >= 1 && rec.room_no < 101)
        {
        gotoxy(36,15);cout<<"Single"<<rec.room_type;
        }
    	else
    	if (rec.room_no > 100 && rec.room_no < 201)
    	{
    	gotoxy(36,15);cout<<"Twin"<<rec.room_type;
    	}
    		else if
    		(rec.room_no >200 && rec.room_no < 301)
    		{
    		gotoxy(36,15);cout<<"Presidential"<<rec.room_type;
    		}
    
        gotoxy(25,16);cputs("Duration:");
        gotoxy(36,16);clreol();scanf("%d",&rec.duration);
        gotoxy(25,17);cputs("Price:");
        gotoxy(33,17);cout<<"$";
    
        if (rec.room_no >= 1 && rec.room_no < 101)
        {
        rec.price = 100.00;
        gotoxy(34,17);cout<<rec.price;
        }
    	else
    	if (rec.room_no > 100 && rec.room_no < 201)
    	{
    	rec.price = 150.00;
    	gotoxy(34,17);cout<<rec.price;
    	}
    		else if
    		(rec.room_no >200 && rec.room_no < 301)
    		{
    		rec.price = 200.00;
    		gotoxy(34,17);cout<<rec.price;
    		}
    
    
    
        fflush(stdin);
        gotoxy(25,18);cputs("Payment Type(cash/cheque):");
        gotoxy(53,18);gets(rec.pay_type);
    
        rec.total = rec.price * rec.duration;
    
        gotoxy(25,19);cputs("Total Price charged: $");
        gotoxy(48,19);cout<<rec.total;
    
    
        /*write to file*/
        fp=fopen("checkin.txt","a+");
        fprintf(fp,"%-6s",rec.ic_no);
        fprintf(fp,"%-29s",rec.name);
        fprintf(fp,"%-14s",rec.dob);
        fprintf(fp,"%-14s",rec.nationality);
        fprintf(fp,"%-14s",rec.tel_no);
        fprintf(fp,"%-14s",rec.date_arr);
        fprintf(fp,"%-14s",rec.date_dep);
        fprintf(fp,"%-14s",rec.room_type);
        fprintf(fp,"%4d",rec.room_no);
        fprintf(fp,"%2d",rec.duration);
        fprintf(fp,"%9.2f",rec.price);
        fprintf(fp,"%-7s",rec.pay_type);
        fprintf(fp,"%9.2f",rec.total);
        fprintf(fp,"\n");
        fclose(fp);
       }
       /*get response from user*/
       gotoxy(25,35);clreol();
       cputs("Add another[Y/N]:");
       reply=toupper(getche());
       fflush(stdin);
       fclose(fp);
       }
       return 0;
      }
    
    /*************************************************SEARCH MENU**************************************************/
    
    void search_menu(void)
    {
     int c;
     
      do 
      {
      textbackground(BLACK);
      textcolor(LIGHTGRAY);
    
      clrscr();
    
      gotoxy(30,2);
      cout<<"*****************************";
      gotoxy(30,3);
      cout<<"<< C3 Hotel Billing System >>";
      gotoxy(30,4);
      cout<<"*****************************";
      
      gotoxy(33,7);
      cputs("1.Search Booking Record.");
      gotoxy(33,9);
      cputs("2.Search Check-in Record.");
      gotoxy(33,11);
      cputs("3.Back to Main menu.");
      gotoxy(33,15);
      textcolor(LIGHTGRAY);
      cprintf("ENTER CHOICE [1-3]: ");
    
      fflush(stdin);
      
      c = (getche());
    
      switch(c)
      {
       case '1': searchbook();
    	     break;
    
       case '2': searchcheck();
    	     break;
    
       case '3': break;
    
       default: sound(500);delay(200);nosound(); 	//sound turns the PC speaker on at the specified frequency, nosound turns the PC speaker off.
    	    gotoxy(26,24);
    	    puts("<<--ENTER FROM 1-3 PLEASE-->>");	//This message will only print on INVALID ENTRY and Will ask again for input.
                getch();
      }
     }
     while(c != '3');
    }
    
    /******************************************************SEARCH BOOKING******************************************************/
    
    int searchbook()
    {
     char found='N';
     int reclen=89,recnum=0,pos;
     char bookingID[7],file_name[25],file_nationality[15],file_pay[8],length;
     char file_bookingID[7], file_dob[15], file_tel_no[15],file_date_arr[15],file_date_dep[15], file_room_type[15];
     char dummy;
     float file_price,new_price;
     int file_room_no, file_duration;
    
     FILE *fp;
     clrscr();
     /****print header****/
     gotoxy(25,2);cprintf("Search Booking Record");
     gotoxy(25,3);cprintf("---------------------");
    
     /*****Get booking id from user*****/
     gotoxy(25,4);cprintf("Enter Booking ID:");
     gotoxy(42,4);gets(bookingID);
     fflush(stdin);
    
    
      fp=fopen("booking.txt","r+");
      if(fp==NULL)
      {
       gotoxy(25,25);textcolor(RED+BLINK);cprintf("File does not exist");
       gotoxy(25,27);cprintf("Press any key to continue...");getche();textcolor(BLUE);
      }
      else
      {
       length=strlen(bookingID);
       while(!feof(fp))
       {
        /**get data from file**/
        fgets(file_bookingID,5,fp);
        fgets(file_name,21,fp);   
        fgets(file_dob,15,fp);
        fgets(file_nationality,15,fp);
        fgets(file_tel_no,15,fp);
        fgets(file_date_arr,15,fp);
        fgets(file_date_dep,15,fp);
        fgets(file_room_type,15,fp);
        fscanf(fp,"%d",&file_room_no);
        fscanf(fp,"%d",&file_duration);
        fscanf(fp,"%f",&file_price);
        fscanf(fp,"%c ",&dummy);
        fflush(stdin);
        recnum++;
    
        /**compare both booking id**/
        if(strnicmp(file_bookingID,bookingID,length)==0)
        {
         /**print data on screen**/
    
         gotoxy(25,8);cout<<"Name: ";
         gotoxy(32,8);cout<<file_name;
         
         gotoxy(25,10);cout<<"Date of birth: ";
         gotoxy(40,10);cout<<file_dob;
         
         gotoxy(25,12);cout<<"Nationality: ";
         gotoxy(38,12);cout<<file_nationality;
         
         gotoxy(25,14);cout<<"Telephone Number: ";
         gotoxy(44,14);cout<<file_tel_no;
    
         gotoxy(25,16);cout<<"Date Arrived: ";
         gotoxy(40,16);cout<<file_date_arr;
    
         gotoxy(25,18);cout<<"Date Departure: ";
         gotoxy(42,18);cout<<file_date_dep;
    
         gotoxy(25,20);cout<<"Room Type: ";
         gotoxy(37,20);cout<<file_room_type;
    
         gotoxy(25,22);cout<<"Room Number: ";
         gotoxy(39,22);cout<<file_room_no;
    
         gotoxy(25,24);cout<<"Duration: ";
         gotoxy(36,24);cout<<file_duration;
    
         gotoxy(25,26);cout<<"Price: ";
         gotoxy(25,26);printf("$%.2f",file_price);
         
    
         found='Y';
         rewind(fp);
         pos=(recnum-1)*reclen;
         fseek(fp,pos,0);
         break;
        }
       }
         if(found=='N')
       {
        gotoxy(25,25);cputs("\a");textcolor(RED+BLINK);cprintf("Record Not Found!!");
       }
       fflush(stdin);textbackground(WHITE);textcolor(BLUE);
       gotoxy(25,30);cprintf("Press any key to continue...\n");
       gotoxy(25,43);getche();search_menu();
       fclose(fp);
     }
    return 0;
    }
    
    /*********************************************SEARCH CHECK-IN************************************************/
    
    int searchcheck()
    {
     char found='N';
     int reclen=89,recnum=0,pos;
     char ic_no[8];
     char bookingID[7],file_name[25],file_nationality[15],file_pay[8],length;
     char file_bookingID[7], file_dob[15], file_tel_no[15],file_date_arr[15],file_date_dep[15], file_room_type[15];
     char dummy;
     float file_price,file_total;
     int file_room_no, file_duration;
    
     FILE *fp;
     clrscr();
     /****print header****/
     gotoxy(25,2);cprintf("Search Check In Record");
     gotoxy(25,3);cprintf("---------------------");
    
     /*****Get ic number from user*****/
     gotoxy(25,4);cprintf("Enter IC Number:");
     gotoxy(42,4);gets(ic_no);
     fflush(stdin);
    
    
      fp=fopen("checkin.txt","r+");
      if(fp==NULL)
      {
       gotoxy(25,25);textcolor(RED+BLINK);cprintf("File does not exist");
       gotoxy(25,27);cprintf("Press any key to continue...");getche();textcolor(BLUE);
      }
      else
      {
       length=strlen(ic_no);
       while(!feof(fp))
       {
        /**get data from file**/
        fgets(rec.bookingID,7,fp);
        fgets(rec.name,21,fp);
        fgets(rec.dob,11,fp);
        fgets(rec.nationality,10,fp);
        fgets(rec.tel_no,11,fp);
        fgets(rec.date_arr,11,fp);
        fgets(rec.date_dep,11,fp);
        fgets(rec.room_type,13,fp);
        fscanf(fp,"%d",&rec.room_no);
        fscanf(fp,"%d",&rec.duration);
        fscanf(fp,"%f",&rec.price);
        fscanf(fp, "%d",&rec.total);
        fscanf(fp,"%c ",&dummy);
        fflush(stdin);
        recnum++;
    
        /**compare both ic number**/
        if(strnicmp(rec.ic_no,ic_no,length)==0)
        {
         /**print data on screen**/
    
         gotoxy(25,8);cout<<"Name: ";
         gotoxy(32,8);cout<<rec.name;
         
         gotoxy(25,10);cout<<"Date of birth: ";
         gotoxy(40,10);cout<<rec.dob;
         
         gotoxy(25,12);cout<<"Nationality: ";
         gotoxy(38,12);cout<<rec.nationality;
         
         gotoxy(25,14);cout<<"Telephone Number: ";
         gotoxy(44,14);cout<<rec.tel_no;
    
         gotoxy(25,16);cout<<"Date Arrived: ";
         gotoxy(40,16);cout<<rec.date_arr;
    
         gotoxy(25,18);cout<<"Date Departure: ";
         gotoxy(42,18);cout<<rec.date_dep;
    
         gotoxy(25,20);cout<<"Room Type: ";
         gotoxy(37,20);cout<<rec.room_type;
    
         gotoxy(25,22);cout<<"Room Number: ";
         gotoxy(39,22);cout<<rec.room_no;
    
         gotoxy(25,24);cout<<"Duration: ";
         gotoxy(36,24);cout<<rec.duration;
    
         gotoxy(25,26);cout<<"Price: ";
         gotoxy(33,26);printf("$%.2f",rec.price);
    
         gotoxy(25,26);cout<<"Total Price: ";
         gotoxy(39,26);cout<<rec.total; 
    
         found='Y';
         rewind(fp);
         pos=(recnum-1)*reclen;
         fseek(fp,pos,0);
         break;
        }
       }
         if(found=='N')
       {
        gotoxy(25,25);cputs("\a");textcolor(RED+BLINK);cprintf("Record Not Found!!");
       }
       fflush(stdin);textbackground(WHITE);textcolor(BLUE);
       gotoxy(25,30);cprintf("Press any key to continue...\n");
       gotoxy(25,43);getche();search_menu();
       fclose(fp);
     }
    return 0;
    }
    
    
    /*******************View report menu(option 2 of main menu)**************************/
    void display_menu()
    {
     int c;
     
      do
      {
      textbackground(BLACK);
      textcolor(LIGHTGRAY);
    
      clrscr();
    
      gotoxy(30,2);
      cout<<"*****************************";
      gotoxy(30,3);
      cout<<"<< C3 Hotel Billing System >>";
      gotoxy(30,4);
      cout<<"*****************************";
    
      gotoxy(33,7);
      cputs("1.Display Customer Receipt.");
      gotoxy(33,9);
      cputs("2.Display Booking Records.");
      gotoxy(33,11);
      cputs("3.Display Check-in Records.");
      gotoxy(33,13);
      cputs("4.Back to main ");
      gotoxy(33,15);
      textcolor(LIGHTGRAY);
      cprintf("ENTER CHOICE [1-4]: ");
    
      fflush(stdin);
    
      c = (getche());
    
      switch(c)
      {
       case '1': dis_custrec();
    	     break;
    
       case '2': dis_bookrep();
    	     break;
    
       case '3': dis_checkrep();
    	     break;
    
       case '4': break;
    
       default: sound(500);delay(200);nosound(); 	//sound turns the PC speaker on at the specified frequency, nosound turns the PC speaker off.
    	    gotoxy(26,24);
    	    puts("<<--ENTER FROM 1-4 PLEASE-->>");	//This message will only print on INVALID ENTRY and Will ask again for input.
    	    getch();
      }
     }
     while(c != '4');
    }
    
    /****************************************************************************************************/
    
    int dis_custrec()
    {
     FILE *fp;
    
     char file_item_desc[21],file_supplier[21],file_item_id[7],file_dept[11],file_date[13],file_pay[8],res,dummy;
     int file_quantity,length;
     float file_price,total_price,total_order_price=0;
    
     fp=fopen("checkin.txt","r");
     if(fp==NULL)
     {
      gotoxy(23,21);cprintf("\a");textcolor(RED+BLINK);
      cputs("File does not exist!!!");
      gotoxy(23,23);textcolor(BLUE);
      cprintf("Press any key to continue...");
      getche();
     }
     else
     {
      clrscr();
      /*******************************print heading*****************************/
      printf("                              C3 Hotel and Country Club\n");
      printf("                                    Payment Receipt\n\n");
      printf("--------------------------------------------------------------------------------\n");
      printf("IC No	  Name			Room Type     Room No	  Duration	Price  \n");
      printf("--------------------------------------------------------------------------------\n");
      while(!feof(fp))
      {
       /**get data from file**/
       fgets(rec.ic_no,5,fp);
       fgets(rec.name,18,fp);
       fgets(rec.room_type,15,fp);
       fscanf(fp,"%d",&rec.room_no);
       fscanf(fp,"%f",&rec.price);
       fscanf(fp,"%f",&rec.total);
       fscanf(fp,"%d",&rec.duration);
       fscanf(fp,"%c ",&dummy);
       fflush(fp);
    
       /**print data on screen**/
       printf("%s     %s                    %s            %d             %d           %.2f\n",rec.ic_no, rec.name, rec.room_type, rec.room_no, rec.duration, rec.price);
      }
      printf("--------------------------------------------------------------------------------\n");
      printf("                      Total Price:$%.2f\n",rec.total);
     }
     printf("--------------------------------------------------------------------------------\n");
     fclose(fp);
     printf("Press Any key to continue...");getche();
     display_menu();
     return 0;
    }
    
    /********************************************Display Booking Records*************************************************/
    
    int dis_bookrep()
    {
     FILE *fp;
    
     char file_item_desc[21],file_supplier[21],file_item_id[7],file_dept[11],file_date[13],file_pay[8],res,dummy;
     int file_quantity,length;
     float file_price,total_price,total_order_price=0;
    
     fp=fopen("booking.txt","r");
     if(fp==NULL)
     {
      gotoxy(23,21);cprintf("\a");textcolor(RED+BLINK);
      cputs("File does not exist!!!");
      gotoxy(23,23);textcolor(BLUE);
      cprintf("Press any key to continue...");
      getche();
     }
     else
     {
      clrscr();
      /*******************************print heading*****************************/
      printf("                              C3 Hotel and Country Club\n");
      printf("                                    Booking Records\n\n");
      printf("------------------------------------------------------------------------------\n");
      printf("Booking  Name   Date of  Nationality  Tel    Room   Room  Duration  Price  \n");
      printf("  ID             Birth     	        No     Type   No                       \n");
      printf("------------------------------------------------------------------------------\n");
      while(!feof(fp))
      {
       /**get data from file**/
        fgets(rec.bookingID,5,fp);
        fgets(rec.name,21,fp);
        fgets(rec.dob,15,fp);
        fgets(rec.nationality,15,fp);
        fgets(rec.tel_no,15,fp);
        fgets(rec.room_type,15,fp);
        fscanf(fp,"%d",&rec.room_no);
        fscanf(fp,"%d",&rec.duration);
        fscanf(fp,"%f",&rec.price);
        fscanf(fp,"%c ",&dummy);
        fflush(fp);
    
       /**print data on screen**/
       printf("%s   %s       %s    %s      %s      %s     %d      %d      %.2f\n",rec.bookingID, rec.name, rec.dob, rec.nationality, rec.tel_no, rec.room_type, rec.room_no, rec.duration, rec.price);
      }
      printf("--------------------------------------------------------------------------------\n");
      printf("                                  End of Records                                 ");
     }
     printf("--------------------------------------------------------------------------------\n");
     fclose(fp);
     printf("Press Any key to continue...");getche();
     display_menu();
     return 0;
    }
    
    /********************************************Display Check In Record*****************************************************/
    
    int dis_checkrep()
    {
     FILE *fp;
    
     char dummy;
     int file_quantity,length;
     float total_income;
    
     fp=fopen("checkin.txt","r");
     if(fp==NULL)
     {
      gotoxy(23,21);cprintf("\a");textcolor(RED+BLINK);
      cputs("File does not exist!!!");
      gotoxy(23,23);textcolor(BLUE);
      cprintf("Press any key to continue...");
      getche();
     }
     else
     {
      clrscr();
      /*******************************print heading*****************************/
      printf("                              C3 Hotel and Country Club\n");
      printf("                                    Booking Records\n\n");
      printf("--------------------------------------------------------------------------------\n");
      printf("Booking  Name   Date of  Nationality  Tel    Room   Room  Duration  Payment  \n");
      printf("  ID             Birth     	        No     Type   No              Received \n");
      printf("--------------------------------------------------------------------------------\n");
      while(!feof(fp))
      {
       /**get data from file**/
        fgets(rec.bookingID,5,fp);
        fgets(rec.name,21,fp);
        fgets(rec.dob,15,fp);
        fgets(rec.nationality,15,fp);
        fgets(rec.tel_no,15,fp);
        fgets(rec.room_type,15,fp);
        fscanf(fp,"%d",&rec.room_no);
        fscanf(fp,"%d",&rec.duration);
        fscanf(fp, "%f",&rec.total);
        fscanf(fp,"%c ",&dummy);
        fflush(fp);
    
    
       /**calculate total income*****/
       total_income = total_income + rec.total;
    
       /**print data on screen**/
       printf("%s   %s       %s    %s      %s      %s     %d      %d      %.2f\n",rec.bookingID, rec.name, rec.dob, rec.nationality, rec.tel_no, rec.room_type, rec.room_no, rec.duration, rec.total);
      }
      printf("--------------------------------------------------------------------------------\n");
      printf("                         Total Income = $%f.2",total_income                       );
     }
     printf("--------------------------------------------------------------------------------\n");
     fclose(fp);
     printf("Press Any key to continue...");getche();
     display_menu();
     return 0;
    }

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    That's 1032 lines of non-portable code that few of us could compile, full of practices that are very problematic in modern C++, and the only hint is that it doesn't give you the result you are expecting?

    Perhaps you could narrow it down a bit? Which functions are working and which are not? Have you tested it etc?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    3
    Code:
    int searchbook()
    {
     char found='N';
     int reclen=89,recnum=0,pos;
     char bookingID[7],file_name[25],file_nationality[15],file_pay[8],length;
     char file_bookingID[7], file_dob[15], file_tel_no[15],file_date_arr[15],file_date_dep[15], file_room_type[15];
     char dummy;
     float file_price,new_price;
     int file_room_no, file_duration;
    
     FILE *fp;
     clrscr();
     /****print header****/
     gotoxy(25,2);cprintf("Search Booking Record");
     gotoxy(25,3);cprintf("---------------------");
    
     /*****Get booking id from user*****/
     gotoxy(25,4);cprintf("Enter Booking ID:");
     gotoxy(42,4);gets(bookingID);
     fflush(stdin);
    
    
      fp=fopen("booking.txt","r+");
      if(fp==NULL)
      {
       gotoxy(25,25);textcolor(RED+BLINK);cprintf("File does not exist");
       gotoxy(25,27);cprintf("Press any key to continue...");getche();textcolor(BLUE);
      }
      else
      {
       length=strlen(bookingID);
       while(!feof(fp))
       {
        /**get data from file**/
        fgets(file_bookingID,5,fp);
        fgets(file_name,21,fp);   
        fgets(file_dob,15,fp);
        fgets(file_nationality,15,fp);
        fgets(file_tel_no,15,fp);
        fgets(file_date_arr,15,fp);
        fgets(file_date_dep,15,fp);
        fgets(file_room_type,15,fp);
        fscanf(fp,"%d",&file_room_no);
        fscanf(fp,"%d",&file_duration);
        fscanf(fp,"%f",&file_price);
        fscanf(fp,"%c ",&dummy);
        fflush(stdin);
        recnum++;
    
        /**compare both booking id**/
        if(strnicmp(file_bookingID,bookingID,length)==0)
        {
         /**print data on screen**/
    
         gotoxy(25,8);cout<<"Name: ";
         gotoxy(32,8);cout<<file_name;
         
         gotoxy(25,10);cout<<"Date of birth: ";
         gotoxy(40,10);cout<<file_dob;
         
         gotoxy(25,12);cout<<"Nationality: ";
         gotoxy(38,12);cout<<file_nationality;
         
         gotoxy(25,14);cout<<"Telephone Number: ";
         gotoxy(44,14);cout<<file_tel_no;
    
         gotoxy(25,16);cout<<"Date Arrived: ";
         gotoxy(40,16);cout<<file_date_arr;
    
         gotoxy(25,18);cout<<"Date Departure: ";
         gotoxy(42,18);cout<<file_date_dep;
    
         gotoxy(25,20);cout<<"Room Type: ";
         gotoxy(37,20);cout<<file_room_type;
    
         gotoxy(25,22);cout<<"Room Number: ";
         gotoxy(39,22);cout<<file_room_no;
    
         gotoxy(25,24);cout<<"Duration: ";
         gotoxy(36,24);cout<<file_duration;
    
         gotoxy(25,26);cout<<"Price: ";
         gotoxy(25,26);printf("$%.2f",file_price);
         
    
         found='Y';
         rewind(fp);
         pos=(recnum-1)*reclen;
         fseek(fp,pos,0);
         break;
        }
       }
         if(found=='N')
       {
        gotoxy(25,25);cputs("\a");textcolor(RED+BLINK);cprintf("Record Not Found!!");
       }
       fflush(stdin);textbackground(WHITE);textcolor(BLUE);
       gotoxy(25,30);cprintf("Press any key to continue...\n");
       gotoxy(25,43);getche();search_menu();
       fclose(fp);
     }
    return 0;
    }
    ok lets start with this...

    after typing in the unique ID, results should be shown below it..
    however all the data gone upside down..
    what i mean is, the data is not well positioned...

    here is the screenshot.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    Well, I might start off giving you some advice.
    Indentation is a little poor. Try using 4 spaces or 1 tab everywhere you indent. It'll look much better and more readable.
    fflush(stdin) is undefined, meaning anything can happen, so stay away from
    Code:
    that.gotoxy(25,30);cprintf("Press any key to continue...\n");
    Try to not do that - instead put all that code on separate lines. You've done this a lot and it hurts readability.

    Code:
    while(!feof(fp))
    It's usually bad to use feof as loop control. You should probably read the FAQ for more information.

    Code:
     char bookingID[7],file_name[25],file_nationality[15],file_pay[8],length;
     char file_bookingID[7], file_dob[15], file_tel_no[15],file_date_arr[15],file_date_dep[15], file_room_type[15];
    This also looks like a mess. Perhaps it would be better if you put them on separate lines. It would be easier to see all the variables you've declared then.

    Your screenshot is so small, I couldn't get a good look at it either...
    Last edited by Elysia; 12-31-2007 at 04:27 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21