I'm trying to learn C#, I made this calculator with my current knowledge. It works as I intended, but I'd appreciate some input on my code.
using System;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
double input1;
string input2;
double input3;
Console.WriteLine("Super cool calculator 1.0");
Console.WriteLine("This can perform +, -, / or * with two numbers.");
try
{
Console.WriteLine("Enter first number:");
input1 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter operator (+, -, /, *)");
input2 = Console.ReadLine();
Console.WriteLine("Enter second number:");
input3 = Convert.ToDouble(Console.ReadLine());
Calculate(input1, input2, input3);
}
catch (Exception e)
{
Console.WriteLine("Wrong Input! Try again!");
Main(null);
}
}
static void Calculate(double n1, string n2, double n3)
{
string op = n2;
switch (op)
{
case "+":
Console.WriteLine($"The answer is {n1} + {n3} = {n1 + n3}");
Main(null);
break;
case "-":
Console.WriteLine($"The answer is {n1} - {n3} = {n1 - n3}");
Main(null);
break;
case "/":
Console.WriteLine($"The answer is {n1} / {n3} = {n1 / n3}");
Main(null);
break;
case "*":
Console.WriteLine($"The answer is {n1} * {n3} = {n1 * n3}");
Main(null);
break;
default:
Console.WriteLine("Invalid Operation!");
Main(null);
break;
}
}
}
}
Main(null)
calls :). Later today I will leave a proper review. \$\endgroup\$