Calculator as Console Application

Oct 24 2018 4:18 AM
Hallo,
 
I'm going to develop a simple calculator in Console Application (in Visual Studio).
For this task I have use Methods for the operations.
Here I wrote a piece of code
but it doesnt semm to work good when I start the program to check for the math operations:
 
//First the methods
static double Addieren(double plusA, double plusB)
{
return plusA + plusB;
}
static double Multiplizieren(double multiA, double multiB)
{
return multiA * multiB;
}
//methods call in Main method
public static void Main()
{
Console.WriteLine("Bitte Starten Sie eine Taschen Rechenoperation ein: ");
double x, y;
x = Convert.ToDouble(Console.ReadLine());
y = Convert.ToDouble(Console.ReadLine());
char result;
result = Convert.ToChar(Console.ReadLine());
switch (result)
{
case '+':
Console.WriteLine("Bitte Geben Sie eine Rechenoperation ein", Addieren(x, y));
break;
case '*':
Console.WriteLine("Bitte Geben Sie eine Rechenoperation ein", Multiplizieren(x, y));
break;
default:
Console.WriteLine("FEHLER!! Probier es nochmal...");
break;
}
Console.WriteLine("Rechneroperation fertig!");
}
//In the output console I get: erro exception by X (exatly where x must be read with "console.read")
 
Can you test it too, please? What is the mistake?
 
PS: According to the task of the teacher, I have to use the methods!
 
Best regards
Giovanni

Answers (2)