C# trouble with "switch" statement
I copied a program example from "Programming in the key of C#" by charles petzold.
using System;
class calculator
{
static void Main()
{
double Num1, Num2, Result = 0;
bool GotOperation;
Console.Write("Enter first number: ");
Num1 = Double.Parse(Console.ReadLine());
Console.Write("Enter second number: ");
Num2 = Double.Parse(Console.ReadLine());
do
{
Console.Write("Enter the operation (+, -, *, /, %): ");
string op = Console.ReadLine().Trim();
Console.WriteLine("op = {0}" ,op);
GotOperation = true;
switch (op)
{
case "+":
Result = Num1 + Num2;
break;
case "-":
Result = Num1 - Num2;
break;
case "*":
Result = Num1 * Num2;
break;
case "/":
Result = Num1 / Num2;
break;
case "%":
Result = Num1 % Num2;
break;
default:
Console.WriteLine("Operation {0} is not valid",op);
GotOperation = false;
break;
}
}
while (GotOperation);
Console.WriteLine("The result is " + Result);
}
}
See the output. The program doesn't go past I entered the operation.Do I forgot something?
Output:
john@john-Aspire-M1300:~/Documenten$ mono calculator.exe
Enter first number: 45
Enter second number: 9
Enter the operation (+, -, *, /, %): *
op = *
Enter the operation (+, -, *, /, %): +
op = +
Enter the operation (+, -, *, /, %):
|