-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab7.cpp
210 lines (202 loc) · 9.6 KB
/
Lab7.cpp
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
// Lab7.cpp : Defines the entry point for the console application.
/*
EECS20_Lab7.c
Jonathan Lim
33104333
*/
//For some reason, my switch-case always runs twice.
#include "stdafx.h"
#include <stdio.h>
#include <assert.h>
/*int economyClass(int e, int seats[200]);
int businessClass(int b, int seats[200]);
int firstClass(int f, int seats[200]);*/
int main()
{
int seats[200] = {};
char choice, response;
int e = 100, b = 50, f = 0, count = 0;
bool loop;
while (count < 200) {
printf("Hey there! Please type E for 'Economy', type B for 'Business', and type F for 'First Class'.\n");
scanf("%c", &choice);
switch(choice) {
case 'E':
loop = true;
do {
if (seats[e] != 1 && e < 200) {
seats[e] = 1;
count++;
printf("Boarding pass: seat number %d for the economy class.\n", e + 1);
e++;
break;
}
else {
while (loop) {
printf("It seems like the economy class is full. Would you like to book other sections? Type 'y' for yes and 'n' for no.\n");
scanf("%c", &response);
if (response == 'y') {
break;
}
else if (response == 'n') {
printf("We are booked.\n");
break;
}
else {
printf("Type only 'y' or 'n'\n");
loop = false;
}
}
}
} while (e < 200);
break;
case 'B':
loop = true;
do {
if (seats[b] != 1 && b < 100) {
seats[b] = 1;
count++;
printf("Boarding pass: seat number %d in business class.\n", b + 1);
b++;
break;
}
else {
while (loop) {
printf("It seems like the business class is full. Would you like to book other sections? Type 'y' for yes and 'n' for no.\n");
scanf("%c", &response);
if (response == 'y') {
break;
}
else if (response == 'n') {
printf("We are booked.\n");
break;
}
else {
printf("Type only 'y' or 'n'\n");
loop = false;
}
b++;
}
}
} while (b < 100);
break;
case 'F':
loop = true;
do {
if (seats[f] != 1 && f < 50) {
seats[f] = 1;
printf("Boarding pass: seat number %d in first class.\n", f + 1);
f++;
break;
}
else {
while (loop) {
printf("It seems like the first class is full. Would you like to book other sections? Type 'y' for yes and 'n' for no.\n");
scanf("%c", &response);
if (response == 'y') {
break;
}
else if (response == 'n') {
printf("We are booked.\n");
break;
}
else {
printf("Type only 'y' or 'n'\n");
loop = false;
}
}
}
} while (f < 50);
break;
default:
printf("Please type only 'E', 'B', or 'F'.\n");
}
}
printf("Every seat is booked!\n");
return 0;
}
/*int economyClass(int e, int seats[200]) {
char response = NULL;
do {
if (seats[e] != 1) {
seats[e] = 1;
printf("Boarding pass: seat number %d for the economy class.\n", e + 1);
e++;
break;
}
else {
while (1) {
printf("It seems like the economy class is full. Would you like to book other sections? Type 'y' for yes and 'n' for no.\n");
scanf("%c", &response);
if (response == 'y') {
break;
}
else if (response == 'n') {
printf("We are booked.\n");
break;
}
else {
printf("Type only 'y' or 'n'\n");
}
}
}
} while (e < 200);
return e;
}
int businessClass(int b, int seats[200]) {
char response = NULL;
do {
if (seats[b] != 1) {
seats[b] = 1;
printf("Boarding pass: seat number %d in business class.\n", b + 1);
b++;
break;
}
else {
while (1) {
printf("It seems like the business class is full. Would you like to book other sections? Type 'y' for yes and 'n' for no.\n");
scanf("%c", &response);
if (response == 'y') {
break;
}
else if (response == 'n') {
printf("We are booked.\n");
break;
}
else {
printf("Type only 'y' or 'n'\n");
}
b++;
}
}
} while (b < 100);
return b;
}
int firstClass(int f, int seats[200]) {
char response = NULL;
do {
if (seats[f] != 1) {
seats[f] = 1;
printf("Boarding pass: seat number %d in first class.\n", f + 1);
f++;
break;
}
else {
while (1) {
printf("It seems like the first class is full. Would you like to book other sections? Type 'y' for yes and 'n' for no.\n");
scanf("%c", &response);
if (response == 'y') {
break;
}
else if (response == 'n') {
printf("We are booked.\n");
break;
}
else {
printf("Type only 'y' or 'n'\n");
}
}
}
} while (f < 50);
return f;
}*/