Write a simple calculator program that adds, subtracts, multiplies and divides.
ID: 3617220 • Letter: W
Question
Write a simple calculator program that adds, subtracts, multiplies and divides. When
the program is run, it initiliazes the result to 0. The user can then type in an operator
and number. The result is updated and displayed. The following operators are valid:
Operator Meaning
--------------------------------
+ Addition
- Subtraction
* Multiplication
/ Division
---------------------------------
Handle the case when the user enters q or Q to quit and h or H for usage help.
Example output:
Result: 0
Enter operator from the table below, Q or q for quit, H or h for help :
Operator Meaning
======== =======
+ Add
- Subtract
* Multiply
/ Divide
+
Enter the value : 23
0 + 23
Result: 23
Enter operator from the table below, Q or q for quit, H or h for help :
/
Enter the value : 0
Error:Divide by zero. Operation ignored
Result: 23
Enter operator from the table below, Q or q for quit, H or h for help :
Operator Meaning
======== =======
+ Add
- Subtract
* Multiply
/ Divide
*
Enter the value : 3
23 * 3
Result: 69
Enter operator from the table below, Q or q for quit, H or h for help :
Operator Meaning
======== =======
+ Add
- Subtract
* Multiply
/ Divide
-
Enter the value : 56
69 - 56
Result: 13
Enter operator from the table below, Q or q for quit, H or h for help :
Operator Meaning
======== =======
+ Add
- Subtract
* Multiply
/ Divide
/
Enter the value : 4
13 / 4
Result: 3.25
Enter operator from the table below, Q or q for quit, H or h for help :
Operator Meaning
======== =======
+ Add
- Subtract
* Multiply
/ Divide
u
Invalid Entry! Please retry.
Enter operator from the table below, Q or q for quit, H or h for help :
Operator Meaning
======== =======
+ Add
- Subtract
* Multiply
/ Divide
h
Use '+' to add a value to the result ( 3.25 ),
Use '-' to subtract a value from the result ( 3.25 ),
Use '*' to multiply a value with the result ( 3.25 ),
Use '' to divide a value into the result ( 3.25 ),
Result: 3.25
Enter operator from the table below, Q or q for quit, H or h for help :
Operator Meaning
======== =======
+ Add
- Subtract
* Multiply
/ Divide
q
Thank you for using our calculator. Come back again :-)