This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 769
/
mahesh1
134 lines (118 loc) · 4.32 KB
/
mahesh1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//Hotels room booking and order food system in c language
#include <stdio.h>
#include <stdbool.h>
#define NUM_ROOMS 10
#define MAX_ITEMS 5
void initializeRooms(int roomNumbers[], bool isBooked[], int numRooms) {
int i;
for (i = 0; i < numRooms; i++) {
roomNumbers[i] = i + 1;
isBooked[i] = false;
}
}
void displayRooms(int roomNumbers[], bool isBooked[], int numRooms) {
int i;
printf("Room Status:\n");
for (i = 0; i < numRooms; i++) {
printf("Room %d: %s\n", roomNumbers[i], isBooked[i] ? "Booked" : "Available");
}
}
void bookRoom(int roomNumbers[], bool isBooked[], int numRooms, int roomNumber) {
if (roomNumber < 1 || roomNumber > numRooms) {
printf("Invalid room number.\n");
return;
}
if (isBooked[roomNumber - 1]) {
printf("Room %d is already booked.\n", roomNumber);
} else {
isBooked[roomNumber - 1] = true;
printf("Room %d has been booked.\n", roomNumber);
}
}
void displayMenu(char *items[], float prices[], int numItems) {
int i;
printf("Menu:\n");
for (i = 0; i < numItems; i++) {
printf("%d. %s - $%.2f\n", i + 1, items[i], prices[i]);
}
}
float calculateTotal(float prices[], int quantities[], int numItems) {
float total = 0;
int i;
for (i = 0; i < numItems; i++) {
total += prices[i] * quantities[i];
}
return total;
}
int main() {
int roomNumbers[NUM_ROOMS];
bool isBooked[NUM_ROOMS];
initializeRooms(roomNumbers, isBooked, NUM_ROOMS);
char *menuItems[MAX_ITEMS] = {"Burger", "Pizza", "Pasta", "Salad", "Fries"};
float itemPrices[MAX_ITEMS] = {5.99, 8.99, 6.49, 4.99, 2.99};
int quantities[MAX_ITEMS] = {0};
int numRooms = sizeof(roomNumbers) / sizeof(roomNumbers[0]);
int numItems = sizeof(menuItems) / sizeof(menuItems[0]);
int choice;
int roomNumber, quantity;
do {
printf("\nHotel Management and Order System\n");
printf("1. Room Management\n");
printf("2. Order Food\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\nRoom Management\n");
printf("1. Display Room Status\n");
printf("2. Book a Room\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
displayRooms(roomNumbers, isBooked, numRooms);
break;
case 2:
printf("Enter the room number to book: ");
scanf("%d", &roomNumber);
bookRoom(roomNumbers, isBooked, numRooms, roomNumber);
break;
default:
printf("Invalid choice. Please try again.\n");
}
break;
case 2:
printf("\nHotel Order System\n");
displayMenu(menuItems, itemPrices, numItems);
printf("%d. Checkout\n", numItems + 1);
printf("Enter your choice: ");
scanf("%d", &choice);
if (choice >= 1 && choice <= numItems) {
printf("Enter the quantity for %s: ", menuItems[choice - 1]);
scanf("%d", &quantity);
quantities[choice - 1] += quantity;
} else if (choice == numItems + 1) {
float total = calculateTotal(itemPrices, quantities, numItems);
printf("\nReceipt:\n");
int i;
for (i = 0; i < numItems; i++) {
if (quantities[i] > 0) {
printf("%s x%d - $%.2f\n", menuItems[i], quantities[i], itemPrices[i] * quantities[i]);
}
}
printf("Total: $%.2f\n", total);
printf("Thank you for your order!\n");
} else {
printf("Invalid choice. Please try again.\n");
}
break;
case 3:
printf("Exiting the program.\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 3);
return 0;
}