Coder_
Coder_

Reputation: 19

How can I fix No argument given that corresponds to the required formal parameter?

I'm getting an error that says There is no argument given that corresponds to the required formal parameter 'employee' of 'Job_Form(Program.Employee, Program.Job, Program.Job, Program.Job)

I know that is something to do with not passing parameter however then when I pass in the parameter I get another error saying Program.Employee is type that is not valid in given context

namespace company
{
    class Program
    {
        public class Employee
        {
            public Guid Id { get; set; }
            public string Name { get; set; }
            public int Age { get; set; }
            public int IQ { get; set; }
            public string CurrentJob {get;set;}
        }
        public class Job
        {
            public Guid Id { get; set; }
            public string JobDescription { get; set; }
            public int IQRequired { get; set; }
            public int Salary { get; set; }
            public bool Available { get; set; }
        }
        static void Main(string[] args)
        {      
            void Create_Jobs()
            {
                Job Job1 = new Job();
                Job1.Id = Guid.NewGuid();
                Job1.JobDescription = "CEO";
                Job1.IQRequired = 100;
                Job1.Salary = 100000;
                Job1.Available = false;

                Console.WriteLine("Jobs Avaiable \n");
                Console.WriteLine(Job1.JobDescription + "\n IQ Required  :" + Job1.IQRequired + "\nSalary :" + Job1.Salary +"\n");                
            }
            void Create_Employee()
            {
                Employee employee = new Employee();
                employee.Id = Guid.NewGuid();
                Console.WriteLine("Enter Name");
                employee.Name = Console.ReadLine();
                Console.WriteLine("Enter Age");
                employee.Age = Convert.ToInt16(Console.ReadLine());
                Console.WriteLine("Enter Age");
                employee.CurrentJob = "empty";
                Random Rnd = new Random();
                employee.IQ = Rnd.Next();
            }
            void Job_Form(Employee employee,Job Job1)
            {
                Console.WriteLine("what job Would you like:");

                if (Console.ReadLine() == "1" && (employee.IQ >= 50) && (Job1.Available == true))
                {
                    Console.WriteLine("You have been Hired");
                }
                else
                {
                    Console.WriteLine("Sorry we werent able to take you on ");
                }
            }
            Create_Jobs();
            Create_Employee();
            Job_Form(Employee employee, Job Job1);
        }
    }
}

Upvotes: 0

Views: 80

Answers (1)

Sardelka
Sardelka

Reputation: 493

Don't specify argument type in method call.

Job_Form(employee, Job1);

Edit:

Another issue as mentioned in comments.

Modify the two local functions to the following:

            // Change return type from void to Job
            Job Create_Jobs()
            {
                Job Job1 = new Job();
                Job1.Id = Guid.NewGuid();
                Job1.JobDescription = "CEO";
                Job1.IQRequired = 100;
                Job1.Salary = 100000;
                Job1.Available = false;

                Console.WriteLine("Jobs Avaiable \n");
                Console.WriteLine(Job1.JobDescription + "\n IQ Required  :" + Job1.IQRequired + "\nSalary :" + Job1.Salary +"\n");
               
               // return created object        
               return Job1;        
            }

            // Change return type from void to Employee
            Employee Create_Employee()
            {
                Employee employee = new Employee();
                employee.Id = Guid.NewGuid();
                Console.WriteLine("Enter Name");
                employee.Name = Console.ReadLine();
                Console.WriteLine("Enter Age");
                employee.Age = Convert.ToInt16(Console.ReadLine());
                Console.WriteLine("Enter Age");
                employee.CurrentJob = "empty";
                Random Rnd = new Random();
                employee.IQ = Rnd.Next();

                // return created object
                return employee;
            }

Since Job1 and employee is defined in a different scope, the compiler won't know where they come from, therefore an error.

Now that the method returns the created object, you can use it in the Main method:

var Job1 = Create_Jobs();
var employee = Create_Employee();
Job_Form(employee, Job1);

Upvotes: 2

Related Questions