Mohammed Musekula

Mohammed Musekula

  • NA
  • 36
  • 10.9k

C# program that simulates a simple calculator

Mar 24 2015 2:15 PM

How do I to?:

Write a C# program that simulates a simple calculator. Initially, the user chooses an operation:

Please choose an operation (+,-,*,/):+

Repeat that user input until he/she has entered one of the four operator symbols (+, ­, *, /). Then, ask the user needs to enter two double operands:

Please enter first operand: 12.34

Please enter second operand: 45.67

Repeat that user input until the user has entered two numbers.

Now use a “switch” statement to test for the four different operands:

Switch

(operator) {

case “+”:

result = addNumbers (first, second);

break;

...

}

Each operand triggers invoking a separate method (a​ddNumber,​

s​ubtractNumber,​ multiplyNumber,​ d​ivideNumber)​ and assigning the result to a d​ouble​variable “result”. Finally, print out:

The result of <first> <operator> <second> is: <result>.

 
 

Answers (3)