-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticketGenerator.h
89 lines (65 loc) · 2.47 KB
/
ticketGenerator.h
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Define color codes
#define RED "\033[1;31m"
#define GREEN "\033[1;32m"
#define YELLOW "\033[1;33m"
#define BLUE "\033[1;34m"
#define CYAN "\033[1;36m"
#define RESET "\033[1;0m"
void generate_ticket(const char *hotel_name,const char *room_tpye, unsigned int n_rooms, unsigned int p_per_room, Car_Modal *car, const char *car_company_name, const char *car_type, const char *location, int days) {
char name[30], email[30];
char contact [15] ;
// getting the client credentils for generating the ticket
printf("%s\n"GREEN"=> "RESET,
"Please Enter Your Name: ");
scanf("%29[^\n]", name);
while (getchar()!='\n');
printf("\n%s\n"GREEN"=> "RESET,
"Please Enter Your Phone Number: ");
scanf("%14[^\n]", contact);
while (getchar()!='\n');
printf("\n%s\n"GREEN"=> "RESET,
"Please Enter Your Email: ");
scanf("%29[^\n]", email);
while (getchar()!='\n');
char filename[50];
strcpy (filename, "./tickets/");
strcat(filename, name);
strcat(filename, "_receipt.csv");
FILE *fptr;
if ((fptr = fopen( filename, "w") ) == NULL) {
puts("FILE ERROR!");
exit(7);
}
// Write header to the CSV file
fprintf(fptr, "----Receipt for Booking----\n\n");
fprintf(fptr, "Name: %s\n", name);
fprintf(fptr, "Phone: %s\n", contact);
fprintf(fptr, "Email: %s\n", email);
fprintf(fptr, "\n----Booking Details----\n");
fprintf(fptr, "Location: %s\n", location);
fprintf(fptr, "Number of days: %d\n", days);
if ( 0 != strcmp (hotel_name, "") ){
fprintf(fptr, "\nhotel name: %s\n", hotel_name);
fprintf(fptr, "Room Type: %s\n", room_tpye);
fprintf(fptr, "Number of Rooms: %d\n", n_rooms);
fprintf(fptr, "Price per room: %d\n", p_per_room);
}
if ( NULL != car ) {
fprintf(fptr, "\nCar Rental Company name: %s\n", car_company_name);
fprintf (fptr, "Car type: %s\n", car_type);
fprintf(fptr, "Car Model-name: %s\n", car->name);
fprintf(fptr, "Car Model: %d\n", car->modal);
fprintf(fptr, "Car price: %d\n", car->price);
}
int total_cost;
if (NULL != car)
total_cost = ((p_per_room * n_rooms) * days) + (car->price * days);
else
total_cost = ( (p_per_room * n_rooms) * days );
fprintf(fptr, "\nTotal Cost: %d\n", total_cost);
// fprintf(fptr, "Number of Days: %d\n", days/);
fclose(fptr);
}