The goal of this assignment is to practise using loops (for, while,
do), if/else and switch statements and flow charts.
Read through the ENTIRE assignment before you begin.
This assignment is worth 2% of your semester grade -- i.e., it will be marked out of 20 points.
For this assignment, you will write a program that emulates a simple calculator.
First, the program should ask (or "prompt") the user to enter an operator to perform either addition, subtraction, multiplication, (integer) division or modulus. We haven't learned how to input characters yet, so you will have to use numbers to indicate which operator to use. For example, if the user enters a 1, then addition should be performed. Here's what the prompt line should look like:
enter an operator (1 for +, 2 for -, 3 for *, 4 for /, 5 for %, 6 to quit):
Next, your program should prompt the user to enter two numbers (integers). Here's what this prompt line should look like:
enter two numbers:
Next, your program should read in the two numbers and store them in integer variables. Then, your program should perform the requested operation and output the answer.
Finally, your program should loop back to the "enter an operator" prompt, repeating these steps until the user specifies that s/he wants to quit.
Here's a sample run. The numbers in big, bold
font were entered by the user. The rest was output by the computer.
1. Create a flow chart for the program. I strongly suggest that you do this before you write any code. You must hand in the flow chart along with your hard copy. The drawing does not need to be done on the computer. Freehand drawing is fine, as long as it is neat and legible. (5 points)
2. Write the program, using a sentinel controlled while loop to control how many times to ask for an operator and two numbers. Use a switch statement to determine which calculation to perform, based on the operator entered. Name your program <your-user-name>-ass3.c (e.g., sklarel-ass3.c). (11 points)
3. Make sure you do the following: