-
Notifications
You must be signed in to change notification settings - Fork 0
/
arobert6_5_1.cpp
225 lines (180 loc) · 4.06 KB
/
arobert6_5_1.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#include <iostream>
#include <string>
using namespace std;
void print_menu();
int input_choice();
char input_type();
int input_age();
double compute_rate();
void input_reservation(int f[], int g[], int h[], int j);
void print_all(int f[], int g[], int h[]);
int main()
{
int choice;
int total;
char type;
int i = 0;
int hang[100] = { 0 };
int fly[100] = { 0 };
int glide[100] = { 0 };
do {
choice = input_choice();
if (choice == 1)
{
total = i + 1;
input_reservation(fly, glide, hang, i);
i++;
}
else if (choice == 2)
{
print_all(fly, glide, hang);
}
else if (choice == 3)
{
type = input_type();
if (type == 'f' || type == 'F')
{
for (int j = 0; ; j++)//for (int j = 0; fly[j] < 1; j++) why no workie?? Nor does a do while
{
if (fly[j] <= 0)break;
cout << "A patron aged " << fly[j] << " reserved a session of flying." << endl;
}
}
else if (type == 'g' || type == 'G')
{
for (int j = 0; ; j++)
{
if (glide[j] <= 0)break;
cout << "A patron aged " << glide[j] << " reserved a session of gliding." << endl;
}
}
else if (type == 'h' || type == 'H')
{
for (int j = 0; ; j++)
{
if (hang[j] <= 0)break;
cout << "A patron aged " << hang[j] << " reserved a session of hang-gliding." << endl;
}
}
}
} while (choice != 4);
cout << "there were a total of " << total << " reservations." << endl;
return 0;
}
void print_menu()
{
cout << "Welcome to Dare-Devils Recreational Company!" << endl;
cout << "We would be glad to help you make a reservation for your eventual death!!" << endl;
cout << "Please pick from the follwoing menu." << endl;
cout << "1. Add a new reservation" << endl;
cout << "2. Print all reservations" << endl;
cout << "3. Print all reservations for a given sport" << endl;
cout << "4. Quit" << endl;
}
int input_choice()
{
int choice;
print_menu();
do {
cin >> choice;
} while (choice > 0 && choice > 5);
return choice;
}
char input_type()
{
char sport;
do {
cout << "Please enter f/F for flying, g/G for gliding and h/H for hang-gliding" << endl;
cin >> sport;
} while (sport != 'f' && sport != 'F' && sport != 'g' && sport != 'G' && sport != 'h' && sport != 'H');
return sport;
}
int input_age()
{
int age;
do {
cout << "Please enter the age of the patron, minimum 16" << endl;
cin >> age;
if (age > 112)
{
cout << "Sorry, we can't accomodate civil war vets at this time." << endl;
}
else if (age < 16)
{
cout << "Even if I wanted to throw you out a plane, I'm not legally allowed." << endl;
}
} while (age < 16 && age > 111);
return age;
}
double compute_rate(char x, int y)
{
double cost;
if (x == 'f' || x == 'F')
if (y < 26)
{
cost = 68.95;
}
else
{
cost = 55.95;
}
else if (x == 'g' || x == 'G')
if (y < 26)
{
cost = 73.95;
}
else
{
cost = 65.95;
}
else if (x == 'h' || x == 'H')
if (y < 26)
{
cost = 99.95;
}
else
{
cost = 92.95;
}
return cost;
}
void input_reservation(int fly[], int glide[], int hang[], int i)
{
int age, total;
char type;
type = input_type();
if (type == 'f' || type == 'F')
{
age = input_age();
fly[i] = age;
}
else if (type == 'g' || type == 'G')
{
age = input_age();
glide[i] = age;
}
else if (type == 'h' || type == 'H')
{
age = input_age();
hang[i] = age;
}
cout << "$" << compute_rate(type, age);
}
void print_all(int fly[], int glide[], int hang[])
{
for (int j = 0; ; j++)
{
if (fly[j] <= 0)break;
cout << "A patron aged " << fly[j] << " reserved a session of flying." << endl;
}
for (int j = 0; ; j++)
{
if (hang[j] <= 0)break;
cout << "A patron aged " << hang[j] << " reserved a session of hang-gliding." << endl;
}
for (int j = 0; ; j++)
{
if (glide[j] <= 0)break;
cout << "A patron aged " << glide[j] << " reserved a session of gliding." << endl;
}
}