gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
Simple C# calculator with console application
- User
Simple C# calculator with console application
- Assistant
Sure! Here's a simple C# calculator using a console application:
csharp
Simple C# calculator with console application
Sure! Here's a simple C# calculator using a console application:
using System;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Simple Calculator");
Console.Write("Enter the first number: ");
double num1 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the operator (+, -, *, /): ");
char op = Convert.ToChar(Console.ReadLine());
Console.Write("Enter the second number: ");
double num2 = Convert.ToDouble(Console.ReadLine());
double result = 0;
switch (op)
{
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 != 0)
{
result = num1 / num2;
}
else
{
Console.WriteLine("Error: Division by zero is not allowed.");
return;
}
break;
default:
Console.WriteLine("Error: Invalid operator.");
return;
}
Console.WriteLine("Result: " + result);
Console.ReadLine();
}
}
}
In this calculator, the user is asked to enter the first number, the operator (+, -, *, /), and the second number. The program then performs the corresponding operation and displays the result. It includes error handling for division by zero and invalid operators.
Not yet included in a published release.