My calculation, delete and update functions dont work (Programming language C)
Code:
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<time.h>
void menu();
void first();
void p_info();
void options();
void edit();
void pl_int();
void mudroom();
void sauna();
void fitgym();
void coscen();
void y_center();
void bill();
void deleterec();
void updaterec();
void exit();
FILE *TKAE;
struct clientinfo {
int code; //client's pin code//
char f_name[20]; //client's first name//
char l_name[40]; //client's last name//
char country[100]; //client's country//
char date[15]; //date of client's arrival//
char tel_no[20];
}
record; //end structure clientinfo//
int los; //intended length of stay//
float roomcharge; //cost for the rooms//
float expenses; //cost for added expenses//
float discount; //discount given//
float whatyoupay; //what the client will be required to pay//
float payment; //required downpayment//
float totalcharges;
// Constants for the charges//
const float HoneymoonSuite = 900.0; //Base rate - Honeymoon Suite//
const float PenthouseSuite = 850.0; //Base Rate - Penthouse Suite//
const float MasterSuite = 700.0; //Base Rate - Master Suite//
const float Bungalows = 550.0; //Base Rate - Bungalows//
const float BusinessRoom = 400.0; //Base Rate - Business Room//
const float StandardRoom = 250.0; //Base Rate - Standard Room//
const float MakeUpArtist = 40.0; //Make-up Artist//
const float HairStylist = 65.0; //Hairstylist//
const float Manicurist = 40.0; //Manicurist//
const float Pedicurist = 40.0; //Pedicurist//
const float PersonalTrainer = 100.0; //Personal Trainer//
int main()
{
HANDLE hand = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTitle (" TROPICAL KARE AROMATHERAPY AND EUCTICAL HOTEL AND SPA");
printf(" Welcome to the Tropical Kare Aromatherapy and Euctical Hotel and Spa\n");
printf("________________________________________________________________________________\n");
printf("\t\t\t\t\t\t\t 18 Heavenly Boulevard\n");
printf("\t\t\t\t\t\t\t Relaxation Lane\n");
printf("\t\t\t\t\t\t\t Cloud Nine\n");
printf("\t\t\t\t\t\t\t Tel.: 968-7378\n");
printf("\t\t\t\t\t\t\t Email: [email protected]\n\n\n");
printf(" **** where YOU are treated with the royalty and exquisiteness YOU deserve ****\n\n\n\n\n");
system ("pause");
system("cls");
menu();
system ("pause");
return 0;
}
//Display Menu
void menu()
{
int opt;
printf("\t\t\t\tT-KAE HOTEL AND SPA \n");
printf("\t\t\t\t MAIN MENU\n");
printf("________________________________________________________________________________\n\n");
printf("Please select one of the following options:\n\n\n");
printf("1. New Customers\n\n");
printf("2. Edit Existing Customer Information\n\n");
printf("3. Places of Interest\n\n");
printf("4. Exit\n\n");
scanf("%d", & opt);
if (opt==1)
{
system ("cls");
first();
}
if (opt==2)
{
system ("cls");
edit();
}
if (opt==3)
{
system ("cls");
pl_int();
}
if (opt==4)
{
system ("cls");
exit();
}
if (opt>=5)
{
system ("cls");
printf("\tWe're very sorry but that selection is invalid. Please try again.\n\n\n\n\n");
system ("pause");
system ("cls");
menu();
}
//End Menu
}
//First Menu
void first()
{
printf("\t\t\tWelcome to the T-KAE HOTEL AND SPA\n");
printf("\t\t\t PERSONAL INFORMATION PAGE\n");
printf("________________________________________________________________________________\n\n");
p_info();
}
//End of First Menu
//Personal Info. Menu
void p_info()
{
int i;
int y_n;
int selection;
{ FILE *TKAE;
struct clientinfo record={0,"","","","",""};
if (( TKAE = fopen("Doc.txt","a"))==NULL )
{
printf("File could not be opened.\n");//end if//
}
else
{
printf("Please enter your desired PIN code (4 digits only): ");
fscanf(stdin, "%d", & record.code);
printf("\nPlease enter your first name: ");
fscanf(stdin, "%s", & record.f_name);
printf("\nPlease enter your last name: ");
fscanf(stdin, "%s", & record.l_name);
printf("\nKindly enter your country: ");
fscanf(stdin, "%s", & record.country);
printf("\nWhen will you be arriving? (mm/dd/yy) ");
fscanf(stdin, "%s", & record.date);
printf("\nTelephone Number: ");
fscanf(stdin, "%s", & record.tel_no);
fseek(TKAE, (record.code-1) *
sizeof (struct clientinfo), SEEK_SET);
fwrite(&record, sizeof (struct clientinfo), 1, TKAE);
fclose( TKAE );
}
printf("\nHow long will you be staying with us? (days) ");
scanf("%d", & los );
if (los >8)
{
discount=(totalcharges*.05);
}
else
{
discount=0;
}
system("cls");
printf("\t\t\t\tT-KAE HOTEL AND SPA \n");
printf("\t\t\tPERSONAL INFORMATION VERIFICATION SCREEN\n");
printf("________________________________________________________________________________\n\n");
printf("\nPlease verify the following information: \n");
printf("Type '1' for Yes or '2' for No\n\n");
printf("%d (Code) ", record.code);
printf("\n\n%s", record.f_name);
printf(" %s (Name)\n\n", record.l_name);
printf("%s (Parish) \n\n", record.country);
printf("%s (Arrival Date)\n\n", record.date);
printf("%s (Telephone No)\n\n", record.tel_no);
scanf("%d", & y_n);
if (y_n==1)
{
system ("cls");
options();
}
if (y_n==2)
{
system ("cls");
first();
p_info();
}
if (y_n>=3)
{
system ("cls");
printf("\tWe're very sorry but that selection is invalid. Please try again.\n\n\n\n\n");
system ("pause");
system ("cls");
first();
p_info ();
}
}
//End of Personal Info. Menu
}
//Room Selection Menu
void options()
{
int ps;
int hs;
int ms;
int bl;
int br;
int sr;
int choice;
printf("\t\t\t\tT-KAE HOTEL AND SPA \n");
printf("\t\t\t\t ROOM SELECTION\n");
printf("________________________________________________________________________________\n\n");
printf("Kindly select the type of room that you desire\n\n\n");
printf("1. Penthouse Suites\n\n");
printf("2. Honeymoon Suites\n\n");
printf("3. Master Suites\n\n");
printf("4. Bungalows\n\n");
printf("5. Business Rooms\n\n");
printf("6. Standard Rooms\n\n");
printf("7. Main Menu\n\n");
printf("8. View Current Bill\n\n");
scanf("%d", & choice);
if (choice==1)
{
system ("cls");
printf("How many Penthouse Suites do you require?: ");
scanf("%d", & ps);
system ("cls");
options();
}
if (choice==2)
{
system ("cls");
printf("How many Honeymoon Suites do you require?: ");
scanf("%d", & hs);
system ("cls");
options();
}
if (choice==3)
{
system ("cls");
printf("How many Master Suites do you require?: ");
scanf("%d", & ms);
system ("cls");
options();
}
if (choice==4)
{
system ("cls");
printf("How many Bungalows do you require?: ");
scanf("%d", & bl);
system ("cls");
options();
}
if (choice==5)
{
system ("cls");
printf("How many Business Rooms do you require?: ");
scanf("%d", & br);
system ("cls");
options();
}
if (choice==6)
{
system ("cls");
printf("How many Standard Rooms do you require?: ");
scanf("%d", & sr);
system ("cls");
options();
}
if (choice==7)
{
system ("cls");
menu ();
}
if (choice==8)
{
system ("cls");
bill ();
}
if (choice >=9)
{
system ("cls");
printf("\tWe're very sorry but that selection is invalid. Please try again.\n\n\n\n\n");
system ("pause");
system ("cls");
options ();
}
float roomcharge =((ps*PenthouseSuite)+(ms*MasterSuite)+(hs*HoneymoonSuite)+(bl*Bungalows)+
(br*BusinessRoom)+(sr*StandardRoom))*los;
}
//End Room Selection Menu
//Edit Menu
void edit()
{
int cho;
printf("\t\t\t\tT-KAE HOTEL AND SPA \n");
printf("\t\t\t\t EXISTING CUSTOMERS\n");
printf("________________________________________________________________________________\n\n");
FILE *TKAE;
struct clientinfo record = { 0, "", "", "", "", ""};
if ( ( TKAE=fopen("Doc.txt","r") ) == NULL ) {
printf( "File could not be located.\n" );
}
else{
printf (" %-10s %-15s%-15s%-10s%-15s%-15s","PIN CODE","FIRST NAME","SURNAME","DATE","TELEPHONE #","COUNTRY");
printf (" %-10s%-15s%-15s%-10s%-15s%-15s\n","--------","----------","-------","----","-----------","-------");
while ( !feof( TKAE ) ) {
fread( &record, sizeof( struct clientinfo ), 1, TKAE );
/* display record */
if ( record.code != 0 ) {
printf (" %-10d%-15s%-15s%-15s%-15s%-15s\n", record.code, record.f_name, record.l_name, record.date,record.tel_no, record.country);
} /* end if */
} /* end while */
fclose( TKAE ); /* fclose closes the file */
} /* end else */
printf ("\n\n\n\n\nTO EXIT TO MAIN MENU PRESS 0\n");
printf("TO DELETE A RECORD PRESS 1\n");
printf("TO UPDATE A RECORD PRESS 2\n");
scanf ("%d",&cho);
if (cho==0)
{
system ("cls");
menu();
}
if (cho==1)
{
system ("cls");
deleterec();
}
if (cho==2)
{
system ("cls");
updaterec();
}
if (cho>2)
{
system ("cls");
printf("\tWe're very sorry but that selection is invalid. Please try again.\n\n\n\n\n");
system ("pause");
system ("cls");
edit();
}
}
//End Edit Menu
//Places of Interest Menu
void pl_int()
{
int sel;
printf("\t\t\t\tT-KAE HOTEL AND SPA \n");
printf("\t\t\t\tPLACES OF INTEREST\n");
printf("________________________________________________________________________________\n\n");
printf("1. Mud Room\n\n");
printf("2. Sauna\n\n");
printf("3. Fitness Gymnasium\n\n");
printf("4. Yoga Center\n\n");
printf("5. Cosmetology Center\n\n");
printf("6. Main Menu\n\n");
printf("7. View Current Bills\n\n");
scanf("%d", & sel);
system("cls");
if (sel==1)
{
system ("cls");
mudroom();
}
if (sel==2)
{
system ("cls");
sauna();
}
if (sel==3)
{
system ("cls");
fitgym();
}
if (sel==4)
{
system ("cls");
y_center();
}
if (sel==5)
{
system("cls");
coscen();
}
if (sel==6)
{
system("cls");
menu();
}
if (sel==7)
{
system ("cls");
bill ();
}
if (sel>=8)
{
system ("cls");
printf("\tWe're very sorry but that selection is invalid. Please try again.\n\n\n\n\n");
system ("pause");
system ("cls");
pl_int();
}
}
//End Places of Interest Menu
//Mud Room Menu
void mudroom()
{
int op;
printf("\t\tWelcome to the T-KAE HOTEL AND SPA Mud Room\n");
printf("________________________________________________________________________________\n\n");
printf("We have experts from all over the world who are versed in the healing power of a mud bath\n\n");
printf("We can assure you that at the end of your session you will feel as though all"
"your stress and tension have been taken away from you\n\n\n");
printf("\t\tListed below is a list of available times for sessions\n\n\n\n");
printf(" 08:30 - 09:30\n\n");
printf(" 10:00 - 11:00\n\n");
printf(" 02:00 - 03:00\n\n");
printf(" 07:00 - 08:00\n\n");
printf("1. Back\n");
scanf("%d", & op);
if (op==1)
{
system("cls");
pl_int();
}
if (op>=6)
{
system ("cls");
printf("\tWe're very sorry but that selection is invalid. Please try again.\n\n\n\n\n");
system ("pause");
system ("cls");
mudroom();
}
}
//End Mudroom Menu
// Sauna Menu
void sauna()
{
int mm;
printf("\t\t Welcome to the T-KAE HOTEL AND SPA Sauna\n");
printf("________________________________________________________________________________\n\n");
printf("There are two different sauna rooms where you can go to let go off some 'steam';\t\t\t\t one for each sex\n\n");
printf("\t Both saunas are open 24/7 and only guests 15+ are allowed\n\n");
printf("1. Main Menu\n\n");
scanf("%d", & mm);
if (mm==1)
{
system("cls");
pl_int();
}
if (mm>=2)
{
system ("cls");
printf("\tWe're very sorry but that selection is invalid. Please try again.\n\n\n\n\n");
system ("pause");
system ("cls");
sauna();
}
}
// End Sauna Menu
// Fitness Gymnasium Menu
void fitgym()
{
int pt;
printf("\t Welcome to the T-KAE HOTEL AND SPA Fitness Gymnasium\n");
printf("________________________________________________________________________________\n\n");
printf("1. Female Personal Trainer\n\n");
printf("2. Male Personal Trainer\n\n");
printf("3. No Thanks\n\n");
scanf("%d", & pt);
if (pt==1==2)
{
printf("Your selection has been added to your account\n\n");
PersonalTrainer;
system ("pause");
system("cls");
pl_int();
}
if (pt==3)
{
system ("cls");
pl_int();
}
if (pt>=5)
{
system ("cls");
printf("\tWe're very sorry but that selection is invalid. Please try again.\n\n\n\n\n");
system ("pause");
system ("cls");
fitgym();
}
}
// End Fitness Gynasium Menu
//Cosmetology Center Menu
void coscen()
{
int cc;
int type;
printf("\t Welcome to the T-KAE HOTEL AND SPA Cosmetology Center\n");
printf("________________________________________________________________________________\n\n");
printf("1. Makeup Artist\n\n");
printf("2. Manicurist\n\n");
printf("3. Pedicurist\n\n");
printf("4. Hair Stylist\n\n");
printf("5. No thanks\n");
scanf("%d", & type);
if (type==1)
{
printf("Your selection has been added to your account\n\n");
MakeUpArtist;
system("pause");
system("cls");
coscen();
}
if (type==2)
{
printf("Your selection has been added to your account\n\n");
Manicurist;
system("pause");
system("cls");
coscen();
}
if (type==3)
{
printf("Your selection has been added to your account\n\n");
Pedicurist;
system("pause");
system("cls");
coscen();
}
if (type==4)
{
printf("Your selection has been added to your account\n\n");
HairStylist;
system("pause");
system("cls");
coscen();
}
if (type==5)
{
system ("cls");
pl_int();
}
if (type>=6)
{
system ("cls");
printf("\tWe're very sorry but that selection is invalid. Please try again.\n\n\n\n\n");
system ("pause");
system ("cls");
coscen();
}
}
//End Cosmetology Center Menu
//Yoga Center Menu
void y_center()
{
int slect;
printf("\t\t Welcome to the T-KAE HOTEL AND SPA Yoga Center\n");
printf("________________________________________________________________________________\n\n");
printf("\t\tListed below is a list of available times for sessions\n\n\n\n");
printf(" 10:00 - 11:00\n\n");
printf(" 01:00 - 02:00\n\n");
printf(" 04:00 - 05:00\n\n");
printf(" 08:00 - 09:00\n\n");
printf("1. No Thanks\n\n");
scanf("%d", & slect);
if (slect==1)
{
system ("cls");
pl_int();
}
if (slect>=2)
{
system ("cls");
printf("\tWe're very sorry but that selection is invalid. Please try again.\n\n\n\n\n");
system ("pause");
system ("cls");
}
}
void bill()
{
expenses = (MakeUpArtist+Manicurist+Pedicurist+HairStylist+PersonalTrainer);
totalcharges = (expenses + roomcharge) - discount;
payment = totalcharges * .10;
int mm;
printf("\t\t\t\tT-KAE HOTEL AND SPA \n");
printf("\t\t\t\t CURRENT BILL\n");
printf("________________________________________________________________________________\n\n");
printf("Total Charges: $", totalcharges);
printf("\n\nRoom Charges: $", roomcharge);
printf("\n\nMiscellaneous Expenses: $", expenses);
printf("\n\nDiscount: $", discount);
printf("\n\nRequired Downpayment: $", payment);
printf ("\n\n\n\n\n\n\n\n\nTO EXIT TO MAIN MENU PRESS 0\n");
scanf("%d", & mm);
if (mm==0)
{
system("cls");
menu();
}
}
void deleterec()
{
FILE *TKAE;
printf("\t\t\t\tT-KAE HOTEL AND SPA \n");
printf("\t\t\t\tDELETE MENU\n");
printf("________________________________________________________________________________\n\n");
struct clientinfo record= { 0, "", "", "", "", "" };
int pcode;
(record.code = pcode);
printf( "Enter PIN CODE of the account to be deleted: " );
scanf( "%d", &pcode );
fread( &record, sizeof( struct clientinfo ), 1, TKAE );
fseek( TKAE, ( record.code - 1 ) * sizeof( struct clientinfo ), SEEK_SET );
if ( pcode = 0 )
printf( "Account %d does not exist.\n", record.code );
else {
fseek( TKAE, ( record.code - 1 ) *sizeof( struct clientinfo ), SEEK_SET );
fwrite( &record,sizeof( struct clientinfo ), 1, TKAE );
printf("RECORD DELETED!!!\n\n");
system ("pause");
}
system("cls");
main();
}
void updaterec()
{
FILE *TKAE;
struct clientinfo record= { 0, "", "", "", "", "" };
int change;
int pcode;
pcode=record.code;
printf( "Enter PIN CODE of the account to be updated: " );
scanf( "%d", &pcode );
fseek( TKAE, ( pcode - 1 ) * sizeof( struct clientinfo ), SEEK_SET );
fread( &record, sizeof( struct clientinfo ), 1, TKAE );
if ( pcode == 0 )
printf( "Account %d does not exist.\n", pcode );
else {
printf("%-10d%-15s%-15s%-15s%-15s%-15s",record.code, record.f_name, record.l_name, record.tel_no, record.country);
printf("Press '1' to change this account or '2' to go back to the Main Menu");
scanf("%d", & change);
}
if (change==1)
{
}
system("cls");
edit();
}
void exit()
{
printf("\t\tTropical Kare Aromatherapy and Euctical Hotel and Spa\n");
printf("________________________________________________________________________________\n\n");
printf(" The Management and Staff of the T-KAE HOTEL AND SPA hopes that you will enjoy your stay with"
"us and will be delighted if you choose to return and visit with \t\t\t\t\tus again\n\n");
printf("\t\tWE HOPE THAT YOU WILL ENJOY THE REST OF YOUR DAY\n\n\n");
Sleep (2000);
system ("cls");
printf ("\n\n\n\n\n\n\n\n\t\t\t----------------------------------\n\n");
printf ("\n\n");
printf ("\t\t\t----------------------------------\n");
Sleep (200);
system ("cls");
printf ("\n\n\n\n\n\n\n\n\t\t\t----------------------------------\n\n");
printf ("\t\t\t\t EXI\n\n");
printf ("\t\t\t----------------------------------\n");
Sleep (200);
system ("cls");
printf ("\n\n\n\n\n\n\n\n\t\t\t----------------------------------\n\n");
printf ("\t\t\t\t EXITIN\n\n");
printf ("\t\t\t----------------------------------\n");
Sleep (200);
system ("cls");
printf ("\n\n\n\n\n\n\n\n\t\t\t----------------------------------\n\n");
printf ("\t\t\t\t EXITING..\n\n");
printf ("\t\t\t----------------------------------\n");
Sleep (100);
system ("cls");
printf ("\n\n\n\n\n\n\n\n\t\t\t----------------------------------\n\n");
printf ("\t\t\t\t EXITING.....\n\n");
printf ("\t\t\t----------------------------------\n");
Sleep (100);
system ("cls");
printf ("\n\n\n\n\n\n\n\n\t\t\t----------------------------------\n\n");
printf ("\t\t\t\t EXITING.......\n\n");
printf ("\t\t\t----------------------------------\n");
Sleep (1000);
exit (1);
}