In a given transport company (train & bus), people are given discount fares if they meet any of the following requirements:
Write a program that given a person’s age and profession whether they are elegible for a discount fare.
Your program should process multiple lines of input in a single run.
Each line of input
contains a string p and a number a
indicating the profession and age of a person respectively.
For each line of input,
there should be a line of output indicating the type of fare:
full price
or discount
.
Each profession will be given as a single all-lowercase word with no more than thirty characters.
Example input
student 11
programmer 33
retired 66
engineer 44
Example output
discount
full price
discount
full price
The exact meanings of “under”, “up to” and “from” are important in this exercise. Here, “under” means strictly less than (<); “up to” means less than or equal to (≤); and “from” means greater than or equal to (≥). Try to think of edge cases where people are just within the age boundary, what should be the correct output for each?
Though not necessary, it is possible to solve this exercise by resorting to a single boolean check. Can you spot the implicit “and” and “or” connectives from the problem description?
In Haskell and Python,
you can check if two strings are equal using the ==
operator.
To compare two strings in C,
you need to use the strcmp
function.
Using ==
between two strings compares their memory addresses,
which is not what generally you would like to compare.
try first: bool-not bool-and-or age
try also: timetable
Copyright © 2020-2022 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/discount