Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 80301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:16:52+00:00 2026-05-10T21:16:52+00:00

I have a logical error. I provided the following as input: the salary is

  • 0

I have a logical error. I provided the following as input:

  • the salary is 30000
  • the child n° is 9

So the the net salary will be:

  • the family bonus + salary – tax

     (750)       + (30000) - (3000) 
  • but my program count them as

      (1500)    + (30000) + (6000) 

My program doubled (accumulated) the family bonus and the tax. Can anyone explain why?

class Program {     static void Main(string[] args)     {         Employee e = new Employee();         e.ReadEmployee();         e.PrintEmployee();     } }  class Employee {     private string n;     private int byear;     private double sal;     private bool gen;     private bool mar;     private int child;     public static double tax = 0;     public static double familybonus = 0;     public string Ename     {         get { return this.n; }         set         {             this.n = value;          }     }     public int Birthyear     {         get { return this.byear; }         set         {             if (value >= 1970 && value <= 1990) this.byear = value;             else this.byear = 0;         }     }     public double Salary     {         get { return this.sal; }         set         {             if (value >= 5000 && value <= 50000) this.sal = value;             else this.sal = 0;         }     }      public bool Gender     {         get { return this.gen; }         set { this.gen = value; }     }     public bool Married     {         get { return this.mar; }         set { this.mar = value; }     }     public int NChildren     {         get { return this.child; }         set         {             if (value >= 0 && value <= 12) this.child = value;             else this.child = 0;         }     }      public double getAge()     {         return 2008 - this.Birthyear;     }     public double getNet()     {         double net = getFamilyBonus() + this.Salary - getTax();         return net;     }      public double getFamilyBonus()     {          if (this.Married == true)             familybonus += 300;         if (this.NChildren == 1) familybonus += 200;         else if (this.NChildren == 2) familybonus += 350;         else if (this.NChildren >= 3) familybonus += 450;         return familybonus;     }      public double getTax()     {         if (Salary < 10000)             tax = 0;         if (Salary <= 10000 && Salary >= 20000)             tax += Salary * 0.05;         else tax += Salary * 0.1;         return tax;      }      public void ReadEmployee()     {         Console.Write('Enter Employee Name: ');         Ename = Console.ReadLine();         Console.Write('Enter Employee birth date: ');         Birthyear = int.Parse(Console.ReadLine());          while (Birthyear < 1970 || Birthyear > 1990)         {             Console.WriteLine('Invalid Birthyear!');             Console.Write('Enter Employee Birth date: ');              Birthyear = int.Parse(Console.ReadLine());         }         string g = null;         while (g != 'M' && g != 'm' && g != 'F' && g != 'f')         {             Console.Write('Enter Employee Gender (M/F)');             g = Convert.ToString(Console.ReadLine());         }          if (g == 'M' || g == 'm')             Gender = true;         else             Gender = false;         Console.Write('Enter Employee Salary: ');         Salary = Double.Parse(Console.ReadLine());         while (Salary < 5000 || Salary > 50000)         {             Console.WriteLine('Invalid Salary!');             Console.Write('Enter Employee Salary: ');             Salary = int.Parse(Console.ReadLine());         }         string m = null;         while (m != 'true' && m != 'True' && m != 'false' && m != 'False')         {             Console.Write('Married (true/false)');             m = Console.ReadLine();          }         if (m == 'true')             this.Married = true;         else             this.Married = false;          Console.Write('Enter Employee Children count: ');         NChildren = int.Parse(Console.ReadLine());          while (NChildren < 0 || NChildren > 12)         {             Console.WriteLine('Invalid NChildren!');             Console.Write('Enter Employee Children count: ');              NChildren = int.Parse(Console.ReadLine());         }      }     public void PrintEmployee()     {         Console.Write('Hello ');         {             if (Gender == true)                 Console.Write('Mr. ');             else                 Console.Write('Mrs. ');             Console.WriteLine(Ename);         }         Console.WriteLine('You are {0} years old', getAge());         Console.WriteLine('Salary= {0}', Salary);         Console.WriteLine('Tax= {0}', getTax());         Console.WriteLine('Family bonus= {0}', getFamilyBonus());         Console.WriteLine('Net= {0}', getNet());     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:16:53+00:00Added an answer on May 10, 2026 at 9:16 pm

    I took the existing code, and hard-wired the inputs (rather than using Console.ReadLine()), I get:

    You are 28 years old Salary= 30000 Tax= 3000 Family bonus= 750 Net= 25500

    The main problem seems to be not initializing values – i.e. treating fields as variables:

    public double getTax() {     if (Salary < 10000)         tax = 0;     if (Salary <= 10000 && Salary >= 20000)         tax += Salary * 0.05;     else tax += Salary * 0.1;     return tax; } 

    OK – and what does tax start at if Salary >= 10000, etc. Likewise familyBouns in getFamilyBonus. By the way, how can Salary be both <= 10000 and >= 20000?

    To illustrate, I’ve changed the output to:

        Console.WriteLine('Tax= {0}', getTax());     Console.WriteLine('Tax= {0}', getTax());     Console.WriteLine('Tax= {0}', getTax()); 

    Which shows:

    Tax= 3000 Tax= 6000 Tax= 9000

    My advice would be: don’t store calculated values unless you know the math is so complex that it is worth it. Just calculate them as needed (no field at all).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I have a class Employee. I want to be able to Validate() it before
I have a subclass with an over-ridden method that I know always returns a
I get this error on an update panel within a popupControlExtender which is within
For sometime now, I have been trying to wrap my head around the reason

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.