### Thread: Help Please: Income tax calulator with Functions and Robus validation

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
2
Rep Power
0

#### Help Please: Income tax calulator with Functions and Robus validation

Code:
```#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

float tax(float t);
void clear (void);
main()
{
do
{
float income, pc,hi, charity, t, taxincome, net;
char a[0], b[0],c,choose;
int nod,ch,flag=0;
int person = 4000;

printf("\n Choose one of the following options:");
printf("\n 1. Tax calcultor:");
printf("\n 0. Exit");
printf("\n Income tax calculator");
printf("\n =====================");
printf("\n Income for the current month <in thousand VND>:"); scanf("%f%c", &income,&c);
while (1)
{
printf("\n Pension contribution <5%%> y/n?"); scanf("%s", &a);
if (a[0]=='y' || a[0]=='Y' || a[0]=='n' || a[0]=='N')
break;
else
printf("\n You must press 'Y' or 'N' only, try again");
}
printf("\n");
while (1)
{
printf("\n Health insurance <1%%> y/n?"); scanf("%s", &b);
if (b[0]=='y' || b[0]=='Y' || b[0]=='n' || b[0]=='N')
break;
else
printf("\n You must press 'Y' or 'N' only, try again");
}
printf("\n Number of Dependants <18 years old:"); scanf("%d", &nod);
printf("\n Charity:"); scanf("%f", &charity);
if (a[0] =='y' || a[0] == 'Y')
pc=income*0.05;
else
pc=0.0;
if (b[0] == 'y' || b[0] == 'Y')
hi=income*0.01;
else
hi=0.0;
t = income-(4000.0 + pc + hi + 1600.0*nod + charity);
taxincome = tax(t);
printf("\n Gross Income: %.1f", income);
printf("\n Deduction");
printf("\n Personal allowance :    %.1d", person);
printf("\n Pension contribution:   %.1f", pc);
printf("\n Health insurance:       %.1f", hi);
printf("\n Dependant:              %.1f", 1600.0*nod);
printf("\n Charity:                %.1f", charity);
printf("\n -----------------------------");
printf("\n Total:                  %.1f", t);
printf("\n Taxable Income:         %.1f", taxincome);
printf("\n Net income:             %.1f", income-taxincome);
printf("\n =============================");
printf("\n Another run <y/n>?");
}
while (getch() == 'y' || getch() == 'Y');
getch();
}
float tax(float t)
{
float taxincome;
if (t <= 5000)
taxincome = t*0.05;
else if (t <= 10000)
taxincome = 5000*0.05 +(t-5000)*0.1;
else if (t <=18000)
taxincome = 5000*0.05 + 5000*0.1 + (t-10000)*0.15;
else if (t <=32000)
taxincome = 5000*0.05 + 5000*0.1 + 8000*0.15 + (t-18000)*0.2;
else if (t <=52000)
taxincome = 5000*0.05 + 5000*0.1 + 8000*0.15 + 14000*0.2 + (t-32000)*0.25;
else if (t <= 80000)
taxincome = 5000*0.05 + 5000*0.1 + 8000*0.15 + 14000*0.2 + 20000*0.25 + (t-52000)*0.3;
else
taxincome =  5000*0.05 + 5000*0.1 + 8000*0.15 + 14000*0.2 + 20000*0.25 + 28000*0.3 + (t-80000)*0.35;
return taxincome;
}```

• input is negative in value
• more than one decimal point appears in floating-point input
• characters are embedded in numeric input
• character is different from ‘y’ and ‘n’
• gift of charity exceeds the income
• a decimal point appear in integer input
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
2
Rep Power
0
Originally Posted by dwise1_aol