-1

Please, I just got started with C# and I was asked to carry out a basic task.

Question: Write a function that returns the sum of two numbers

Here is my code...

private static int sum;
int add(int param1, int param2) 
{
    Console.WriteLine("Please, enter first number");
    int num1 = int.Parse(Console.ReadLine());
    Console.WriteLine("Please, enter second number");
    int num2 = Convert.ToInt16(Console.ReadLine());
    sum= num1 + num2;
    Console.WriteLine("The value of your first and second number is {0}", sum);
}

What am i getting wrong please?

Sunil
  • 3,404
  • 10
  • 23
  • 31
Godymn
  • 23
  • 7

1 Answers1

0

You are not returning anything from the method.Also you are not using input arguments.

 int add() 
{
    Console.WriteLine("Please, enter first number");
    int num1 = int.Parse(Console.ReadLine());
    Console.WriteLine("Please, enter second number");
    int num2 = Convert.ToInt16(Console.ReadLine());
    sum= num1 + num2;
    Console.WriteLine("The value of your first and second number is {0}", sum);
    return sum;
}
santosh singh
  • 27,666
  • 26
  • 83
  • 129