Hello, I’m working on this task:
Create 4 methods with the names “Add”, “Subtract”, “Multiply”, and “Divide” that return the result of the corresponding mathematical operation between two integers (Return at this point, not print!). Ask the user for the string command and two integer numbers. Depending on the command: “add”, “subtract”, “multiply”, or “divide”, call the correct method, and then print the returned value to the screen. For example:
>multiply
>15
>2
30
Here is my code:
namespace Methods
{
class SimpleCalculator
{
static void Main(string[] args)
{
string command = Console.ReadLine();
int number1 = int.Parse(Console.ReadLine());
int number2 = int.Parse(Console.ReadLine());
if(command == "multiply")
{
int result = Multiply(number1, number2);
Console.WriteLine(result);
}
}
static int Add(int number1, int number2)
{
return number1 + number2;
}
static int Subtract(int number1, int number2)
{
return number1 - number2;
}
static int Multiply(int number1, int number2)
{
return number1 * number2;
}
static int Divide(int number1, int number2)
{
return number1 / number2;
}
}
}
Can anyone please help me to solve it?