Home > Software engineering >  Can someone help me fix the error, "There is no argument given that corresponds to the required
Can someone help me fix the error, "There is no argument given that corresponds to the required

Time:11-25

namespace ConsoleApp4
{
    class Program
    {
        public static int Year(int num1)
        {
            Console.WriteLine("Enter a year.");
            num1 = Convert.ToInt32(Console.ReadLine());
            if (num1 % 4 == 0)
            {
                Console.WriteLine("This is a leap year mate.");
                Console.ReadLine();
            }
            return num1;

        }
        static void Main(string[] args)
        {
            Console.WriteLine(Year());
            Console.ReadLine();
        }
    }
}

CodePudding user response:

You have an unnecessary parameter on public static int Year(int num1) ... you don't need int num1 because you don't even use it. But the error message is because you called Year without giving it a parameter. Your parenthesis were empty:

Year()

It would work if you used Year(0) or gave it some kind of other int parameter, but as you're not even using the parameter you should delete it:

public static int Year() { /* ... your code here */ }

But your error message is what you get whenever you try to call methods or constructors without supplying the proper arguments.

CodePudding user response:

You don't need an input parameter in Year method. Remove it and try this

          public static int Year()
          {
    
            Console.WriteLine("Enter a not leap year.");
            var num1 = Convert.ToInt32(Console.ReadLine());

            while (num1 % 4 == 0)
            {
                Console.WriteLine("This is a leap year mate. Try again");
                num1 = Convert.ToInt32(Console.ReadLine());
            }
            return num1;
         }

     static void Main(string[] args)
    {
        Console.WriteLine(Year());
        Console.WriteLine("Press any key to exit");
        Console.ReadLine();
    }
  • Related