@Singad , based on my research, you could try the following code to make make arithmetical operations in C#.
while (true)
{
Console.WriteLine("Please input x");
double x = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Please input y");
double y = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("// Please input opeartions //");
string z = Console.ReadLine();
switch (z)
{
case "+":
Console.WriteLine("// Result is //");
Console.WriteLine(x+y);
break;
case "-":
Console.WriteLine("// Result is //");
Console.WriteLine(x-y);
break;
case "*":
Console.WriteLine("// Result is //");
Console.WriteLine(x*y);
break;
case "/":
if (y == 0)
{
Console.WriteLine("Result is 0");
}
else
{
Console.WriteLine("// Result is //");
Console.WriteLine(x/y);
}
break;
}
Console.WriteLine("Do you want to exit ?! Y:N?");
char Terminat = Console.ReadKey().KeyChar;
if (Terminat == 'Y' || Terminat == 'y')
{
break;
}
}
Result:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.