Question: Write a Ruby Script that simulates a simple four function calculator without a memory. The operations you should implement are: + - Add - -
Write a Ruby Script that simulates a simple four function calculator without a memory. The operations you should implement are:
+ - Add
- - Subtract
/ - Divide
* - Multiply
Q - Quit Program Error message must be displayed when invalid command is used or attempt to divide by zero. Use a single character as the command for each operation. Heres a sample of the calculator in use:
Enter First Operand: 0
Enter Command (+ - * / C Q): +
Enter Second Operand : 12
Result = 12
Enter First Operand: -4
Enter Command (+ - * / C Q): -
Enter Second Operand : 12
Result = -16
Enter First Operand: 10
Enter Command (+ - * / C Q): *
Enter Second Operand : 5
Result = 50
Enter First Operand: 13
Enter Command (+ - * / C Q): /
Enter Second Operand : 3
Result = 4.333333
Enter First Operand: 13
Enter Command (+ - * / C Q): \
Enter Second Operand : 3
******* ERROR : \ is not a valid command *******
Enter First Operand: 28
Enter Command (+ - * / C Q): /
Enter Second Operand : 0
******* ERROR : Cannot divide by zero *******
Enter First Operand: 15
Command (+ - * / C Q) Q
End
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
