This is a tutorial for hotel management in C.
This program can be used for managing a hotel or a shop.
It helps us to create Bill.
I have programmed it in VS Code.
It will make an ‘.exe’ file so that it can be executed on any computer.
#include <stdio.h> #include <math.h> #include <string.h> #include <time.h> #include <stdlib.h>
First we will include all the header files.
int choice; char save_bill_or_not; int order_no = 0; int total = 0; int active = 1;
Here are the variables and their functions.
choice | To get the user choice. |
save_bill_or_not | To save the bill or not. |
order_no | To get the order no. |
total | To count the total |
active | To check if the user exited or not. |
struct items_details { char item_name[100]; float item_price; int item_quantity; };
- item name
- item price
- item quantity
struct order_details { char customer_name[100]; int no_of_items; struct items_details items_details[100]; int total; int net_total; };
Here we will declare a structure of order details as :
- customer name
- no of items
- total
- net total (after GST and discount)
We have included a structure inside a structure because each order will contain a number of items and we want their details.
struct order_details order[100]; struct order_details order_read;
Then we will declare them with their variables.
void delay(int number_of_seconds) { int milli_seconds = 300 * number_of_seconds; clock_t start_time = clock(); while (clock() < start_time + milli_seconds) ; }
This code allows us to give a delay using the time library.
void generate_menu() { system("cls"); printf("1]Generate Bill\n"); printf("2]Exit\n"); }
Now using this function we will generate a menu.
void generate_bill_head(int no_of_items, char name[100]) { printf("====================================BILL====================================\n"); printf("Bill for :%s \n", name); printf("Date : "); printf(__DATE__); printf("\n"); printf("----------------------------------------------------------------------------\n"); printf("Item\t\t\tQuantity\t\tPrice\t\tTotal\n"); printf("----------------------------------------------------------------------------\n"); }
In this code we will generate the Bill Head. It will have two parameters :
- no_of_items
- name (item name)
void generate_bill_body(char item_name[100], float price, int quantity) { printf("%s\t\t\t%d\t\t\t%f\t%f\n", item_name, quantity, price, (quantity * price)); }
We can generate bill body using this function. It has three parameters :
- item_name
- price
- quantity
void generate_bill_foot(float total) { printf("----------------------------------------------------------------------------\n"); printf("Total\t\t\t\t\t\t\t\t%f\n", total); printf("Discount\t\t\t\t\t\t\t%f\n", (total * 10 / 100)); printf("CGST\t\t\t\t\t\t\t\t%f\n", ((total - (total * 10 / 100)) * 9 / 100)); printf("SGST\t\t\t\t\t\t\t\t%f\n", ((total - (total * 10 / 100)) * 9 / 100)); printf("----------------------------------------------------------------------------\n"); printf("Net Total\t\t\t\t\t\t\t%f\n", ((total - (total * 10 / 100)) + ((total - (total * 10 / 100)) * 18 / 100))); printf("----------------------------------------------------------------------------\n"); printf("Thank you for visiting\n"); order[order_no].net_total = total; order[order_no].net_total = ((total - (total * 10 / 100)) * 9 / 100); }
In this function we will generate the bill foot. It will contain
- Total
- Discount
- GST
- Net Total
It has one parameter :
- total
int main() { while (active) { generate_menu(); printf("Enter your choice : "); scanf("%d", &choice); system("cls"); switch (choice) { case 1: fgetc(stdin); printf("Enter name of customer : "); fgets(order[order_no].customer_name, 100, stdin); printf("Enter no of items : "); scanf("%d", &order[order_no].no_of_items); printf("\n"); for (int i = 0; i < order[order_no].no_of_items; i++) { fgetc(stdin); printf("Enter item no %d name : ", (i + 1)); fgets(order[order_no].items_details[i].item_name, 100, stdin); printf("Enter item no %d price : ", (i + 1)); scanf("%f", &order[order_no].items_details[i].item_price); printf("Enter item no %d quantity : ", (i + 1)); scanf("%d", &order[order_no].items_details[i].item_quantity); printf("\n\n"); order[order_no].items_details[i].item_name[strlen(order[order_no].items_details[i].item_name) - 1] = '\0'; } printf("Generating Bill"); for (int i = 0; i < 5; i++) { delay(1); printf("."); } printf("\n"); printf("\n"); generate_bill_head(order[order_no].no_of_items, order[order_no].customer_name); printf("\n"); for (int i = 0; i < order[order_no].no_of_items; i++) { total = total + (order[order_no].items_details[i].item_price * order[order_no].items_details[i].item_quantity); generate_bill_body(order[order_no].items_details[i].item_name, order[order_no].items_details[i].item_price, order[order_no].items_details[i].item_quantity); } generate_bill_foot(total); order[order_no].total = total; order[order_no].net_total = ((total - (total * 10 / 100)) * 9 / 100); printf("Enter 1 to Finish : "); scanf("%d", &choice); order_no++; break; case 2: printf("Exit\n"); active = 0; break; default: printf("Exit\n"); active = 0; break; } } }
The code written in the main function is as follows:
- First we will create a while loop with argument ‘active’.
- Then we will generate the menu and ask the user for its choice.
- According to user’s choice we will switch using ‘switch’ statement with argument ‘choice’.
- If user enters ‘1’ them we will create a bill. For that first we will ask for his\her name and number of items.
- We will use a for loop, in it we will ask for item name, item price, item quantity. The loop will go on till ‘i‘(iterator) is not greater than or equal to no of items.
- Then we will generate the bill head using ‘generate_bill_head()’.
- We will run a for loop again and use ‘generate_bill_body()’. The loop will run till ‘i'(iterator) is not greater than or equal to no of items.
- Then we will generate the bill foot using ‘generate_bill_foot()’.
- The bill will be generated and displayed on the screen.
- Then we will ‘Enter 1 to finish’ to finish the bill generation process. Then we will return back to menu.
- If the user enters ‘2’ then the program will exit.
Really good program for billing. Great effort Sanskar. keep it up.
One suggestion, you should think of exception handling as well in it.
Подключение офисного интернета: минимальные сроки, оптимальные цены
интернет для офиса в москве https://www.internet-v-ofis1.ru .