user14087778
user14087778

Reputation:

constructor properties

I want to calculate the HRA, DA etc. I have to define a constructor, But the error pops up mentioning that The variable `basic_salary' is assigned but its value is never used.

code:

public void read()
{
    Console.WriteLine("Enter the employee name");
    empname = Console.ReadLine();
    Console.WriteLine("Enter the basic salary of an employee");
    int basic_salary = Convert.ToDouble(Console.ReadLine());
    calculate();
}

class program
{
public static void Main(string[] args)
{
    Employee employeobj = new Employee();
    employeobj.read();
    employeobj.display();
}
}

Upvotes: 0

Views: 136

Answers (1)

Prasad Telkikar
Prasad Telkikar

Reputation: 16049

In read() function you are defining basic_salary variable again, instead of using basic_salary defined at the class level.

To solve your issue, try

public void read()
{
    Console.WriteLine("Enter the employee name");
    empname = Console.ReadLine();
    Console.WriteLine("Enter the basic salary of an employee");
    //insted of defining new integer as basic_salary, use existing class level basic_salary variable
    basic_salary = Convert.ToInt32(Console.ReadLine()); 
    calculate();
}

Upvotes: 1

Related Questions