-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
199 lines (162 loc) · 3.46 KB
/
main.c
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
#include <stdio.h>
int running = 1;
int seatsSold = 0;
struct seat{
char name[100];
int type;
int seatCost;
int seat;
};
struct seat seats[10];
void seatMap()
{
printf("\nSEAT AVAILBILITY\n");
printf("([*] Sold\n");
printf("([ ] Empty\n\n");
for (int loopIndex = 0; loopIndex < (sizeof(seats) / sizeof(seats[0])); loopIndex++)
{
if((loopIndex) %2 == 0)
{
if(seats[loopIndex].seatCost > 0)
{
printf("[*]\t");
}
else
{
printf("[ ]\t");
}
}
if((loopIndex) %2 == 1)
{
if(seats[loopIndex].seatCost > 0)
{
printf("[*]\n");
}
else
{
printf("[ ]\n");
}
}
}
}
int seatCoster(int type)
{
int cost;
if(type == 1)
{
cost = 100 *1.2;
}
if(type == 2)
{
cost = 100 *1;
}
if(type == 3)
{
cost = 100 *1.1;
}
return cost;
}
int mainMenu()
{
int choice = 0;
printf("-------------------------------------");
printf("\nMAIN MENU\n");
printf("\n\t1. Book a seat\n");
printf("\t2. Display all available seats\n");
printf("\t3. Display all passengers\n");
printf("\t4. Exit program\n");
printf("choice: ");
scanf("%d", &choice);
return choice;
}
void bookASeat()
{
printf("\033[0;0H\033[2J");
int choice = 0;
printf("-------------------------------------");
printf("\nBOOK A SEAT\n");
printf("\nWhat Seat would You like");
seatMap();
printf("choice: ");
int validSeatNumber =0;
while(validSeatNumber == 0)
{
choice = 0;
scanf("%d", &choice);
if(seats[choice -1].seatCost >0)
{
printf("\nPlease pick and empty seat\n\n");
printf("choice: ");
}
else
{
seats[choice -1].seat = choice;
validSeatNumber =1;
}
}
seats[seatsSold].seat = seatsSold;
if(seatsSold == 10)
{
printf("\nOut of Seats");
return;
}
printf("\nWhat is customer name: ");
scanf("%s", &seats[choice-1].name);
printf("\nWhat type is the customer");
printf("\n\t1. Busines class\n");
printf("\t2. Local\n");
printf("\t3. pleasure\nchoice:");
scanf("%d", &seats[choice-1].type);
seats[choice-1].seatCost = seatCoster(seats[choice-1].type);
printf("\nThe Seat will cost: £ %d\n", seats[choice-1].seatCost);
seatsSold = seatsSold +1;
}
void displayAllAvailableSeats()
{
printf("\033[0;0H\033[2J");
printf("-------------------------------------");
printf("\nSEAT AVAILBILITY\n");
seatMap();
}
void displayAllPassangers()
{
printf("\033[0;0H\033[2J");
printf("-------------------------------------");
printf("\nALL PASSENGERS\n");
for (int loopIndex = 0; loopIndex < (sizeof(seats) / sizeof(seats[0])); loopIndex++)
{
if(seats[loopIndex].seatCost > 0)
{
printf("\n Passneger %d",loopIndex+1);
printf("\n Name : %s",seats[loopIndex].name);
printf("\n Class : %d",seats[loopIndex].type);
printf("\n Cost : £%d",seats[loopIndex].seatCost);
printf("\n Seat number : %d\n",loopIndex+1);
}
}
}
void main(void)
{
printf("\033[0;0H\033[2J");
int choice = 0;
while(running == 1)
{
choice = mainMenu();
if(choice == 1)
{
bookASeat();
}
else if(choice == 2)
{
displayAllAvailableSeats();
}
else if(choice == 3)
{
displayAllPassangers();
}
else if(choice == 4)
{
running = 0;
}
}
}