Hi,
Can anyone please tell me how to solve this calculator code with using cases?
I really don't know how to conclude it. It doesn't matter if code is long cuz of cases.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
float result;
try
{
Console.Write("Enter the first number: ");
int a = int.Parse(Console.ReadLine());
Console.Write("Enter the operation (+), (-), (*) ali (/): ");
char operation1 = char.Parse(Console.ReadLine());
if (operation1.Equals('+') || operation1.Equals('-') || operation1.Equals('*') || operation1.Equals('/'))
{
Console.Write("Enter the second number: ");
int b = int.Parse(Console.ReadLine());
Console.Write("Enter the operation (+), (-), (*) ali (/): ");
char operation2 = char.Parse(Console.ReadLine());
if (operation2.Equals('+') || operation2.Equals('-') || operation2.Equals('*') || operation2.Equals('/'))
{
Console.Write("Enter the third number: ");
int c = int.Parse(Console.ReadLine());
switch (operation1)
{
case '-':
result = a - b - c;
break;
case '*':
result = a * b * c;
break;
case '+':
result = a + b + c;
break;
case '/':
result = a / b / c;
break;
default:
result = 0;
break;
}
Console.WriteLine("Result: " + Math.Round(result));
}
else
{
Console.WriteLine("Input error!");
}
}
else
{
Console.WriteLine("Input error!");
}
}
catch
{
Console.WriteLine("Input error!");
}
Console.ReadKey();
}
}
}
THANK YOU FOR YOUR HELP.