I am a beginner programmer, I decided to make this calculator program to test my knowledge on basic C# syntax, the code executes as intended, however I would like to shorten it to be more concise.
Console.WriteLine("Please select your first number: ");
double numberOne = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please select your second number: ");
double numberTwo = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please choose the operation: ");
var userInput = Console.ReadLine();
if (userInput == "+")
{
Console.WriteLine(numberOne + numberTwo);
}
else if (userInput == "-")
{
Console.WriteLine(numberOne - numberTwo);
}
else if (userInput == "*")
{
Console.WriteLine(numberOne * numberTwo);
}
else if (userInput == "/")
{
Console.WriteLine(numberOne / numberTwo);
}
Console.WriteLine()
, and the last line in the file is line 28, the closing brace of the finalelse if
block. If OP is just starting with C#, it's likely that their file only contains what's shown in the question (and perhaps are not aware of namespaces,public static void Main
etc.) \$\endgroup\$