- Course
- Functions C
- Main parameter calculator
Main parameter calculator
Last updated:
8/23/2020
⁃
Difficulty:
Intermediate
Create a C# program that serves as a calculator with the possibility of adding, subtracting, multiplying or dividing.
You should analyze the Main parameters to get the input of the exercise.
Input
2 x 2
Output
4
Solution
using System;
public class MainParametersCalculator
{
public static void Main(string[] args)
{
int num1 = Convert.ToInt32(args[0]);
char operation = Convert.ToChar(args[1]);
int num2 = Convert.ToInt32(args[2]);
switch (operation)
{
case '+':
Console.WriteLine(num1 + num2);
break;
case '-':
Console.WriteLine(num1 - num2);
break;
case 'x':
case 'X':
case '*':
Console.WriteLine(num1 * num2);
break;
case '/':
Console.WriteLine(num1 / num2);
break;
}
}
}