Code Wars V

Program / Task Name:

   English Math




Point Value:




Task Description

Create a program that can process simple math problems that are stated in full English words and provide the answer (also in English).  Keep the following in mind when writing your program:

  • Only the numbers one through twenty will be used for inputs or outputs,
  • Only the operators “times”, “divided-by”, “plus”, and “minus” will be used,
  • Input and output should be all in lowercase letters,
  • Correct answers will be integer numbers from one to twenty  - only integer math operations should be used (so fractions or rounding should not be an issue) and intermediate results can go outside the range of 1-20,
  • The input file ( may have up to twenty lines of input,
  • Each line will contain a different math problem,
  • There may be more than one operation per line/problem (maximum of 10 operations per line),
  • The operators have the following order of precedence (when there is more than one operator per line/problem):
    1. “times”
    2. “divided-by”
    3. “plus”
    4. “minus”

A higher precedence means that all operations of that level are performed before ones of the next level.

Answers must be output on separate, consecutive lines (see example below) and correct spelling is required.

Program Input

The input for your program can be found in and looks as follows:

two plus three
five times four minus three
twelve minus six
four divided-by two times two
three times four minus four divided-by two
seven minus one plus twenty divided-by two times five

Program Output

Write the output to a file (prob11.out) as follows:



hp Code Wars
Hello -- Dominos?...
  (c) 2004 Hewlett-Packard Company