-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmetrocard.c
162 lines (118 loc) · 5.04 KB
/
metrocard.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
// Team Solid
// Brandon Lim, Christopher Narducci & Jacob Lindahl
#include <stdio.h>
int main() {
float rides; // number of subway or local bus rides
float express; // number of express bus rides
char living; // living or visiting
printf("====================================================\n");
printf("Welcome to the MetroCard Calculator! - New York City\n");
printf("====================================================\n");
printf("\n");
printf("The fare for a subway or local bus ride: $2.75\n");
printf("The fare for an express bus ride: $6.50\n");
printf("\n");
printf("Do you live here or are you visiting? (Input L/V):");
scanf("%c", &living);
if (living == 'L' || living == 'l') {
float monthlycost; // monthly cost using single fare rides
printf("\n");
printf("How many times do you use the subway/bus a week?:");
scanf("%f", &rides);
printf("\n");
printf("How many times do you use the express bus a week?:");
scanf("%f", &express);
monthlycost = (4 * rides * 2.75) + (4 * express * 6.50);
printf("\n");
printf("============\n");
printf("MONTHLY COST\n");
printf("============\n\n");
printf(" - Using Single Fare Rides $%0.2f\n", monthlycost);
printf(" - Using 7-Day Unlimited Card (x4) $128.00\n");
printf(" - Using 30-Day Unlimited Card $121.00\n");
printf("==============================================\n\n");
if (monthlycost > 121) {
printf("It would be better to use the 30-Day Unlimited.\n");
printf("You would save $%0.2f per month.\n", monthlycost - 121);
}
else {
printf("It would be better to use Single Fare rides.\n");
printf("You would save $%0.2f per month.\n", 121 - monthlycost);
}
}
else if (living == 'V' || living == 'v') {
float days; // number of days
int weeks; // number of weeks (rounded up)
float tripcost; // trip cost using single fare rides
float unlimited; // trip cost using 7-day unlimited
printf("\n");
printf("How many days total are you staying in New York?:");
scanf("%f", &days);
printf("\n");
printf("How many times do you use the subway/bus per day?:");
scanf("%f", &rides);
printf("\n");
printf("How many times do you use the express bus per day?:");
scanf("%f", &express);
tripcost = (days * rides * 2.75) + (days * express * 6.50);
if (days <= 7)
{
weeks = 1;
}
else if (days <= 14)
{
weeks = 2;
}
else if (days <= 21)
{
weeks = 3;
}
else if (days <= 28)
{
weeks = 4;
}
else if (days <= 35)
{
weeks = 5;
}
else if (days <= 42)
{
weeks = 6;
}
else if (days <= 49)
{
weeks = 7;
}
unlimited = weeks * 32.00;
printf("\n");
printf("=========\n");
printf("TRIP COST\n");
printf("=========\n\n");
printf(" - Using Single Fare Rides: $%0.2f\n", tripcost);
printf(" - Using 7-Day Unlimited Card: (x%d) $%0.2f\n", weeks, unlimited);
printf(" - Using 30-Day Unlimited Card: $121.00\n");
printf("================================================\n\n");
if (tripcost < 121 && tripcost < unlimited) {
printf("It would be better to use Single Fare rides.\n");
printf("You would save $%0.2f vs. using 30-Day Unlimited.\n", 121 - tripcost);
printf("You would save $%0.2f vs. using 7-Day Unlimited.\n", unlimited - tripcost);
}
else if (unlimited < tripcost && unlimited < 121) {
printf("It would be better to use the 7-Day Unlimited.\n");
printf("You would save $%0.2f vs. using 30-Day Unlimited.\n", 121 - unlimited);
printf("You would save $%0.2f vs. using Single Fare Rides.\n", tripcost - unlimited);
}
else if (tripcost > 121 && unlimited > 121) {
printf("It would be better to use the 30-Day Unlimited.\n");
printf("You would save $%f vs. using 7-Day Unlimited.\n", unlimited - 121);
printf("You would save $%f vs. using Single Fare Rides.\n", tripcost - 121);
}
}
else {
printf("\n");
printf("=============\n");
printf("Invalid Entry\n");
printf("=============\n");
}
return 0;
}