Skip to content

Instantly share code, notes, and snippets.

@gmarokov
Created January 23, 2019 21:13
Show Gist options
  • Save gmarokov/15f1cf6eaca06bfbe219bfa3851a4387 to your computer and use it in GitHub Desktop.
Save gmarokov/15f1cf6eaca06bfbe219bfa3851a4387 to your computer and use it in GitHub Desktop.
using System;
namespace TaxCalculator
{
class TaxCalculator
{
static void Main(string[] args)
{
int salary;
while(true)
{
Console.WriteLine("Enter salary: ");
var isNumber = int.TryParse(Console.ReadLine(), out salary);
if(!isNumber || salary < 1)
{
Console.WriteLine("Invalid salary. Try again.");
continue;
}
var netSalary = ApplyTax(Convert.ToDecimal(salary));
Console.WriteLine($"Net salary: {netSalary}");
break;
}
}
static decimal ApplyTax(decimal salary)
{
decimal incomeTax = 0.10M;
decimal socialTax = 0.15M;
//If salary is more than 1000 apply income tax
if(salary > 1000)
{
salary -= incomeTax * salary;
//If salary is less than 3000 apply social contribution tax
if(salary < 3000)
{
salary -= socialTax * salary;
}
}
return System.Math.Round(salary, 2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment