-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarwash.c
More file actions
219 lines (188 loc) · 5.9 KB
/
Copy pathcarwash.c
File metadata and controls
219 lines (188 loc) · 5.9 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// Function prototypes
void displayServices();
void bookService();
void viewBooking();
void cancelBooking();
void searchBooking();
void exitApp();
// Structure to store booking details
typedef struct {
char name[50];
char service[50];
char date[20];
} Booking;
Booking bookings[100];
int bookingCount = 0;
// Utility function to get current date
void getCurrentDate(char* buffer) {
time_t t;
struct tm* tm_info;
t = time(NULL);
tm_info = localtime(&t);
strftime(buffer, 20, "%d/%m/%Y", tm_info);
}
// Function to clear the input buffer
void clearBuffer() {
int c;
while ((c = getchar()) != '\n' && c != EOF);
}
// Function to trim newline characters from strings
void trimNewline(char* str) {
str[strcspn(str, "\n")] = '\0';
}
int main() {
int choice;
while (1) {
// Main menu
printf("\n");
printf("========================================\n");
printf(" Welcome to Car Wash Service \n");
printf("========================================\n");
printf("1. View Services\n");
printf("2. Book a Service\n");
printf("3. View Bookings\n");
printf("4. Cancel a Booking\n");
printf("5. Search Booking\n");
printf("6. Exit\n");
printf("========================================\n");
printf("Enter your choice: ");
scanf("%d", &choice);
clearBuffer(); // Ensure input buffer is cleared
switch (choice) {
case 1:
displayServices();
break;
case 2:
bookService();
break;
case 3:
viewBooking();
break;
case 4:
cancelBooking();
break;
case 5:
searchBooking();
break;
case 6:
exitApp();
return 0;
default:
printf("Invalid choice! Please try again.\n");
}
}
return 0;
}
// Function to display available services
void displayServices() {
printf("\n");
printf("========================================\n");
printf(" Available Car Wash Services \n");
printf("========================================\n");
printf("1. Basic Wash - Rs. 300\n");
printf("2. Premium Wash - Rs. 500\n");
printf("3. Interior Cleaning - Rs. 700\n");
printf("4. Complete Detailing - Rs. 1000\n");
printf("========================================\n");
}
// Function to book a service
void bookService() {
Booking newBooking;
printf("\n");
printf("========================================\n");
printf(" Book a Service \n");
printf("========================================\n");
printf("Enter your name: ");
fgets(newBooking.name, sizeof(newBooking.name), stdin);
trimNewline(newBooking.name);
printf("Enter the service (e.g., Basic Wash, Premium Wash): ");
fgets(newBooking.service, sizeof(newBooking.service), stdin);
trimNewline(newBooking.service);
printf("Enter the booking date (DD/MM/YYYY) or press Enter for today: ");
fgets(newBooking.date, sizeof(newBooking.date), stdin);
if (newBooking.date[0] == '\n') {
getCurrentDate(newBooking.date);
} else {
trimNewline(newBooking.date);
}
// Store the booking
bookings[bookingCount++] = newBooking;
printf("Booking confirmed! Thank you, %s.\n", newBooking.name);
}
// Function to view all bookings
void viewBooking() {
if (bookingCount == 0) {
printf("\nNo bookings available.\n");
return;
}
printf("\n");
printf("========================================\n");
printf(" Booking Details \n");
printf("========================================\n");
for (int i = 0; i < bookingCount; i++) {
printf("Booking %d:\n", i + 1);
printf("Name : %s\n", bookings[i].name);
printf("Service : %s\n", bookings[i].service);
printf("Date : %s\n", bookings[i].date);
printf("----------------------------------------\n");
}
}
// Function to cancel a booking
void cancelBooking() {
char name[50];
int found = 0;
if (bookingCount == 0) {
printf("\nNo bookings to cancel.\n");
return;
}
printf("\nEnter the name to cancel booking: ");
fgets(name, sizeof(name), stdin);
trimNewline(name);
for (int i = 0; i < bookingCount; i++) {
if (strcmp(bookings[i].name, name) == 0) {
for (int j = i; j < bookingCount - 1; j++) {
bookings[j] = bookings[j + 1];
}
bookingCount--;
found = 1;
printf("Booking for %s has been canceled.\n", name);
i--; // Adjust index to re-check the current position
}
}
if (!found) {
printf("No booking found for the name: %s\n", name);
}
}
// Function to search for a booking
void searchBooking() {
char name[50];
int found = 0;
if (bookingCount == 0) {
printf("\nNo bookings available to search.\n");
return;
}
printf("\nEnter the name to search: ");
fgets(name, sizeof(name), stdin);
trimNewline(name);
for (int i = 0; i < bookingCount; i++) {
if (strcmp(bookings[i].name, name) == 0) {
printf("\nBooking Found:\n");
printf("Name : %s\n", bookings[i].name);
printf("Service : %s\n", bookings[i].service);
printf("Date : %s\n", bookings[i].date);
printf("----------------------------------------\n");
found = 1;
}
}
if (!found) {
printf("No booking found for the name: %s\n", name);
}
}
// Function to exit the application
void exitApp() {
printf("\nThank you for using the Car Wash Service! Goodbye!\n");
}