Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
- int atoi(const char *string);
- //add more to the sections below if needed-
- //declaring all the procedures to be written later:
- void check_in(), book_tables(), check_out(), menu(), display_rooms(), displayCost();
- void getCost(int n);
- //declaring any constants we will use:
- int room_rates[4] = {100, 85, 75, 50};
- int board_rates[3] = {20, 15, 5};
- //declaring and initiating any global variables we will use:
- int rooms[4] = {1, 1, 1, 1};//room one is the 0th element (1 means free 0 booked)
- int roomUsed[4]; //room number in correct slot
- int tables[2][3] = {{0, 0, 0}, {0, 0, 0}};//Endor, Naboo and Tatooine at 7pm and 9pm respectively
- //since there can only be 4 rooms booked and each person has one of those rooms, the variables for the check in function come in fours:
- const char* table_names[] = {"Endor", "Naboo", "Tatooine"};
- const char *table_time[] = {"7pm", "9pm"};
- char names[4][2][12];
- char IDs[4][12] = {
- {'A', '1'}, {'B', '2'}, {'C', '3'}, {'D', '4'}
- }; //placeholder IDs
- int DOB[4][8] = {{0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}};
- int board_type[4] = {0, 0, 0, 0};//1:FB 2:HB 3:BB
- int length[4] = {0, 0, 0, 0};
- int numChild[4] = {0,0,0,0}; //number of each type per room
- int numAdult[4] = {0,0,0,0};
- int numElderly[4] = {0,0,0,0};
- int newspaper[4] = {0, 0, 0, 0};
- //for check_out
- float costNP = 5.5;
- float childMultiply = 0.5;
- float elderlyMultiply = 0.9;
- char currentID[12];
- float currentRoom;
- int guestPos; //to use as reference in arrays 0-3
- float roomCost = 0;
- float boardCost = 0;
- float tableCost = 0;
- float newsCost = 0;
- float totalCost = 0;
- int freeSpace[4] = {1,1,1,1}; //1 = free, 0 = used
- int userPos;
- struct guestUser
- {
- int inUse; // 0 is free, 1 is taken
- int used;
- char bookingID[12];
- int room;
- int board;
- int length;
- int news; //1 is yes
- int numChild;
- int numAdult;
- int numOld;
- };
- struct guestUser guest1, guest2, guest3, guest4, guestC, guestE; //c is current, e is empty
- int main(void)
- {
- guest1.inUse = 0;
- guest2.inUse = 0;
- guest3.inUse = 0;
- guest4.inUse = 0;
- menu();
- }
- //main menu function
- void menu()
- {
- int option = 1;
- printf("Menu Options, press:\n1 for checking in\n2 for table booking\n3 for checking out\n4 for exit\n");
- fflush(stdin);
- scanf("%d", &option);
- switch (option)
- {
- case 1:
- check_in();
- break;
- case 2:
- book_tables();
- break;
- case 3:
- check_out();
- break;
- case 4:
- break;
- default:
- printf("That wasn't an option");
- menu();
- }
- }
- //check in function
- void check_in()
- {
- //temporary variables to store the user input before it is integrated into the global database
- char first_name[12], second_name[12], date_of_birth[8];
- int num_children = 0, num_adults = 0, num_elderly = 0, room = 0, daily_newspaper = 0;
- if(guest1.inUse ==0)
- {
- guest1.inUse = 1;
- guestC = guest1;
- guestC.used = 1;
- }
- else if(guest2.inUse==0)
- {
- guest2.inUse = 1;
- guestC = guest2;
- guestC.used = 2;
- }
- else if(guest3.inUse ==0)
- {
- guest3.inUse = 1;
- guestC = guest3;
- guestC.used = 3;
- }
- else if(guest4.inUse==0)
- {
- guest4.inUse = 1;
- guestC = guest4;
- guestC.used = 4;
- }
- else
- {
- printf("fully booked");
- menu();
- }
- //getting and saving relevant data
- printf("Please enter your first name:\n");
- fflush(stdin);
- scanf("%s", first_name);
- printf("Please enter your second name:\n");
- fflush(stdin);
- scanf("%s", second_name);
- printf("Please enter your date of birth in the form [DDMMYYYY]:\n");
- fflush(stdin);
- scanf("%s", date_of_birth);
- printf("Please enter the number of children staying:\n");
- fflush(stdin);
- scanf("%d", &num_children);
- printf("Please enter the number of adults between 18 and 65 staying:\n");
- fflush(stdin);
- scanf("%d", &num_adults);
- printf("Please enter the number of adults over 65 staying:\n");
- fflush(stdin);
- scanf("%d", &num_elderly);
- guestC.numChild = num_children;
- guestC.numAdult = num_adults;
- guestC.numOld = num_elderly;
- //checking if too many people
- if((num_children + num_adults + num_elderly) > 4)
- {
- printf("the maximum number of people is 4\n");
- menu();
- return;
- }
- //displays available rooms
- display_rooms();
- printf("which room would you like to stay in?\n");
- fflush(stdin);
- scanf("%d", &room);
- room -= 1;
- rooms[room] = 0;
- guestC.room = room;
- //adding data to global data structure
- for(int j = 0; j < strlen(first_name); j++)
- {
- names[room][0][j] = first_name[j];
- }
- for(int k = 0; k < strlen(second_name); k++)
- {
- names[room][1][k] = second_name[k];
- }
- for(int l = 0; l < 8; l++)
- {
- DOB[room][l] = date_of_birth[l] - 48;
- }
- numChild[room] = num_children;
- numAdult[room] = num_adults;
- numElderly[room] = num_elderly;
- //last pieces of relevant data
- printf("Please enter length of stay (in days):");
- fflush(stdin);
- scanf("%d", &length[room]);
- printf("Please chose which board type:\n1 - full board\n2 - half board\n3 - bed and breakfast\n");
- fflush(stdin);
- scanf("%d", &board_type[room]);
- printf("Would you like the daily newspaper?\n1 - yes\n2 - no\n");
- fflush(stdin);
- scanf("%d", &daily_newspaper);
- guestC.board = board_type[room];
- guestC.news = daily_newspaper;
- guestC.length = length[room];
- if(daily_newspaper == 1)
- {
- newspaper[room] = 1;
- }
- else
- {
- newspaper[room] = 0;
- }
- //generating randomized ID from second name and random number
- for(int m = 0; m < strlen(second_name); m++)
- {
- IDs[room][m] = second_name[m];
- }
- for(int n = 0; n < 4; n++)
- {
- srand(time(NULL)+n*30000);
- IDs[room][n+strlen(second_name)] = rand()%10+48;
- }
- printf("Your booking ID is %s\n\n", IDs[room]);
- strcpy(guestC.bookingID, IDs[room]);
- guestC.used = room;
- roomUsed[userPos]= room;
- menu();
- }
- //displaying available rooms function
- void display_rooms() {
- printf("The available rooms are:\n");
- for (int i = 0; i < 4; i++) {
- if (rooms[i] == 1) {
- printf("room %d - £%d\n", i+1, room_rates[i]);
- }
- }
- }
- //book tables function
- void book_tables()
- {
- // ask for the booking id
- char bookingid[13];
- printf("Enter booking ID: ");
- fflush(stdin);
- scanf("%s", bookingid);
- int roomid = -1;
- // try and find a matching user with that booking id
- for(int t = 0; t < 4; t++){
- if (strcmp(IDs[t], bookingid )==0){
- roomid = t;
- }
- }
- if(roomid == -1){
- printf("Your booking id is not on our database\n");
- return menu();
- }
- int board = board_type[roomid];
- if (board == 3){
- printf("You can't book a table, due to you being in Bed and breakfast\n");
- return menu();
- }
- int table_availability = 0;
- for(int table = 0; table < 3; table++){
- for(int time = 0; time < 2; time++){
- if(tables[time][table] == 0){
- table_availability = 1;
- }
- //printf("%d" , tables[time][table]);
- }
- }
- if(table_availability == 1){
- printf("The following tables are available: \n");
- }
- else{
- printf("There are no tables available");
- return menu();
- }
- int option = 0;
- for(int table = 0; table < 3; table++){
- for(int time = 0; time < 2; time++){
- option++;
- if(tables[time][table] == 0){
- // printf("Tables available: \n");
- printf("%d . %s %s \n",option, table_names[table], table_time[time]);
- }
- //printf("%d" , tables[time][table]);
- }
- }
- int selection_table = 0;
- printf("What table would you like to book? \nEnter number:");
- fflush(stdin);
- scanf("%d", &selection_table);
- switch (selection_table){
- case 1:
- tables[0][0] = 1;
- printf("Your table has been booked\n");
- break;
- case 2:
- tables[1][0] = 1;
- printf("Your e has been booked\n");
- break;
- case 3:
- tables[0][1] = 1;
- printf("Your e has been booked\n");
- break;
- case 4:
- tables[1][1] = 1;
- printf("Your e has been booked\n");
- break;
- case 5:
- tables[0][2] = 1;
- printf("Your e has been booked\n");
- break;
- case 6:
- tables[1][2] = 1;
- printf("Your e has been booked\n");
- break;
- default:
- printf("You have entered an invalid number\n");
- }
- menu();
- }
- //check out function
- void check_out()
- {
- int validID = 0;
- float cost;
- while(validID != 1)
- {
- printf("enter ID:");
- fflush(stdin);
- // gets(currentID);
- scanf("%s", ¤tID);
- for(int i = 0; i<4; i++)
- {
- if(strcmp(currentID, IDs[i]) == 0)
- {
- printf("valid ID\n");
- validID = 1;
- guestPos = i;
- }
- }
- }
- getCost(guestPos);
- displayCost();
- if(guestC.used ==1)
- {
- guest1 = guestE;
- guestC = guestE;
- }
- else if(guestC.used==2)
- {
- guest1 = guestE;
- guestC = guestE;
- }
- else if(guestC.used ==3)
- {
- guest1 = guestE;
- guestC = guestE;
- }
- else if(guestC.used==4)
- {
- guest1 = guestE;
- guestC = guestE;
- }
- menu();
- }
- void getCost(int n)
- {
- roomCost =guestC.length*(guestC.numChild * room_rates[guestC.room] +
- guestC.numAdult * room_rates[guestC.room] +
- elderlyMultiply*guestC.numOld * room_rates[guestC.room]);
- boardCost = guestC.length*(childMultiply * guestC.numChild * board_rates[guestC.board-1] +
- guestC.numAdult * board_rates[guestC.board-1] +
- guestC.numOld * board_rates[guestC.board-1]);
- if(guestC.news == 1)
- {
- newsCost = 5.5;
- }
- totalCost = roomCost + boardCost + newsCost;
- }
- void displayCost()
- {
- printf("Bill for %s\n", currentID);
- printf("Rooms: %f\n", roomCost);
- printf("Boards: %f\n", boardCost);
- if(newsCost == 5.5)
- {
- printf("Newspaper: %f\n", newsCost);
- }
- printf("Total: %f\n", totalCost);
- //:)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement