index | submit | rank | book

discount – Fare discount

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.

A train.

Input and Output

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

Scoring

Hints

  1. 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?

  2. 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?

  3. In Haskell and Python, you can check if two strings are equal using the == operator.

  4. 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

try next: bool-calc intersect

index | submit | rank | book

Copyright © 2020-2022 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/discount