วันจันทร์ที่ 1 กันยายน พ.ศ. 2557

EX 1 : Task#3 - Tax Calculator



byte   i;
long  income;
double tax,total;
double ft0,ft1,ft2,ft3,ft4,ft5,ft6,t;

void setup()
{
  size(500,100);
}

void draw()
{
  size(500,100);
  background(0);
  fill(0);
  textSize(15);
  fill(20,255,20);
  input_income();
  print_income();
  cal_tax();
  print_tax();
}

void input_income()
{
  if(i==0)
  {
    if(keyPressed)
    {
      if(key == 48)  {income = income*10+0;i=1;}
      if(key == 49)  {income = income*10+1;i=1;}
      if(key == 50)  {income = income*10+2;i=1;}
      if(key == 51)  {income = income*10+3;i=1;}
      if(key == 52)  {income = income*10+4;i=1;}
      if(key == 53)  {income = income*10+5;i=1;}
      if(key == 54)  {income = income*10+6;i=1;}
      if(key == 55)  {income = income*10+7;i=1;}
      if(key == 56)  {income = income*10+8;i=1;}
      if(key == 57)  {income = income*10+9;i=1;}
    }
  }
}

void keyPressed()
{
  if(keyCode==BACKSPACE)
  {
    reset();
  }
}

void keyReleased()
{
  i=0;
}

void cal_tax()
{
  ft0=150000*0.00;
  ft1=150000*0.05;
  ft2=200000*0.10;
  ft3=250000*0.15;
  ft4=250000*0.20;
  ft5=1000000*0.25;
  ft6=2000000*0.30;
  if      (income>4000000) {t=(income-4000000)*0.35; tax=t+ft0+ft1+ft2+ft3+ft4+ft5+ft6;}
  else if (income>2000000) {t=(income-2000000)*0.30; tax=t+ft0+ft1+ft2+ft3+ft4+ft5;}
  else if (income>1000000) {t=(income-1000000)*0.25; tax=t+ft0+ft1+ft2+ft3+ft4;}
  else if (income >750000) {t=(income-750000) *0.20; tax=t+ft0+ft1+ft2+ft3;}
  else if (income >500000) {t=(income-500000) *0.15; tax=t+ft0+ft1+ft2;}
  else if (income >300000) {t=(income-300000) *0.15; tax=t+ft0+ft1;}
  else if (income >150000) {t=(income-150000) *0.05; tax=t+ft0;}
  else                     {t=(income)        *0.00; tax=t;}
}

void print_income()
{
  if(income>29000000){text("Error : Income out of range(max 29000000)", 20, 40);}
  else{text("Please input your income here(max 29000000) = "+income, 20, 40);}
}

void print_tax()
{
  if(income>29000000){text("Tax = N/A", 20, 70);}
  else{text("Tax = "+tax, 20, 70);}
}

void reset()
{
  income=0;
  i=0;
  tax=0;
  total=0;
  ft0=0;
  ft1=0;
  ft2=0;
  ft3=0;
  ft4=0;
  ft5=0;
  ft6=0;
  t=0;
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น