MTRX1702 Lecture 2: MTRX1702, lec 2 Assignment 2-Calculator
Document Summary
You are required to write a program that calculates and displays the result of arbitrary mathematical expressions entered by the user: when the program is run, it is to display a short welcome message. Simple calculator: the program shall display a simple prompt waiting for user input, the following help message shall be displayed whenever the user types the letter h at the input prompt. / division: the program shall exit if the user types the letter q at the input prompt. Before exiting it should print the following message: Error: illegal input: on detection of divide-by-zero, the following error message shall be displayed: This means that rules are required for precedence of operators as infix notation can be ambiguous. If you convert the input string to postfix notation there is no ambiguity and evaluating the expression becomes a series of stack operations.