Ticket Rules
Completed
Read age and whether the person is a student (y/n). Price: under 5 free, under 18 or students 120, 60+ 100, otherwise 200. Print the price.
Input
n, then n lines age y|n.
Output
n lines.
Example
Input
5 3 n 12 n 25 y 70 n 40 n
Output
0 120 120 100 200
Editor
C++
Hints
|| means or; the order of the checks decides which rule wins.
Solution explanation
Note the 65-year-old student pays 120 because the student rule is checked first.
Show solution
#include <iostream>
using namespace std;
int main() {
int n, age;
char student;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> age >> student;
int price;
if (age < 5) price = 0;
else if (age < 18 || student == 'y') price = 120;
else if (age >= 60) price = 100;
else price = 200;
cout << price << "\n";
}
return 0;
}