Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include <stdbool.h>
- #include<string.h>
- #include<conio.h>
- bool isValidYN(char letter)
- {
- if(letter =='y'||letter == 'n')
- return true;
- else
- return false;
- }
- bool isValidNumber(char * string)
- {
- for(int i = 0; i < strlen( string ); i ++)
- {
- if (string[i] < 48 || string[i] > 57)
- return false;
- }
- return true;
- }
- struct acc
- {
- char name[100];
- float income, nGift, nDependant, tax, taxable, nPen, nIns, code, net;
- };
- void display_options();
- void acc_create();
- void acc_display();
- void acc_search(float);
- struct acc account[20];
- int num_acc;
- int main()
- {
- float n;
- char option;
- num_acc=0;
- while(1)
- {
- display_options();
- printf("Enter your choice: ");
- option = getch();
- switch(option)
- {
- case '1':
- acc_create();
- break;
- case '2':
- acc_display();
- break;
- case '3':
- printf("\nEnter employee code to search: ");
- scanf("%f", &n);
- acc_search(n);
- break;
- default :
- system("cls");
- break;
- }
- }
- }
- void display_options()
- {
- printf("\nChoose one of these following options: \n");
- printf("1. Enter a list of employee \n");
- printf("2. Display tax information \n");
- printf("3. Search an employee buy code \n");
- printf("0. Exit \n");
- }
- void acc_create()
- {
- float nIncome, nGift, nDependant, nCode, nPen, nIns, tax, taxable, net;
- char name[50], income[50], pension, health, dependant[5], gift[50], code[5];
- fflush(stdin);
- printf("\nEnter personal information: \n");
- start1:
- printf("Enter your code: ");
- scanf("%s", code);
- if(atof(code)==0)
- exit(main);
- if(!(isValidNumber(code)))
- {
- printf("Invalid input, re-enter: \n");
- goto start1;
- }
- nCode=atof(code);
- printf("Enter your name: ");
- fflush(stdin);
- gets(name);
- start2:
- printf("Income for the current month (in thounsand VND): ");
- scanf("%s", &income);
- if(!(isValidNumber(income)))
- {
- printf("Invalid input, re-enter: \n");
- goto start2;
- }
- nIncome=atof(income);
- start3:
- printf("Pension contributions (5%) y/n?: ");
- scanf("%s", &pension);
- if(!(isValidYN(pension)))
- {
- printf("Invalid input, re-enter: \n");
- goto start3;
- }
- if(pension=='y')
- nPen=nIncome*0.05;
- else
- nPen=0;
- start4:
- printf("Health Insurance (1%) y/n?: ");
- scanf("%s", &health);
- if(!(isValidYN(health)))
- {
- printf("Invalid input, re-enter: \n");
- goto start4;
- }
- if(health=='y')
- nIns=nIncome*0.01;
- else
- nIns=0;
- start5:
- printf("Number of dependants < 18 years old: ");
- scanf("%s", &dependant);
- nDependant=atof(dependant);
- if(!(isValidNumber(dependant)))
- {
- printf("Invalid input, re-enter: \n");
- goto start5;
- }
- start6:
- printf("Gift of charity: ");
- scanf("%s", &gift);
- nGift=atof(gift);
- if(!(isValidNumber(gift))||nGift>nIncome)
- {
- printf("Invalid input, re-enter: \n");
- goto start6;
- }
- float value=nIncome-(4000+nIncome*0.05+nIncome*0.01+nDependant*1600+nGift);
- if(value<=5000)
- tax=value*0.05;
- if(5000<value<=10000)
- tax=5000*0.05+(value-5000)*0.1;
- if(10000<value<=20000)
- tax=5000*0.05+5000*0.1+(value-10000)*0.15;
- if(20000<value<=30000)
- tax=5000*0.05+5000*0.1+10000*0.15+(value-20000)*0.2;
- if(30000<value<=50000)
- tax=5000*0.05+5000*0.1+10000*0.15+10000*0.2+(value-30000)*0.25;
- if(50000<value<=80000)
- tax=5000*0.05+5000*0.1+10000*0.15+10000*0.2+20000*0.25+(value-50000)*0.3;
- if(80000<value)
- tax=5000*0.05+5000*0.1+10000*0.15+10000*0.2+20000*0.25+30000*0.3+(value-80000)*0.35;
- strcpy(account[num_acc].name,name);
- account[num_acc].code=nCode;
- account[num_acc].income=nIncome;
- account[num_acc].nPen=nPen;
- account[num_acc].nIns=nIns;
- account[num_acc].nDependant=nDependant;
- account[num_acc].nGift=nGift;
- account[num_acc].taxable=nIncome-(4000+nIncome*0.05+nIncome*0.01+nDependant*1600+nGift);
- account[num_acc].tax=tax;
- account[num_acc].net=nIncome-tax;
- num_acc++;
- }
- void acc_display()
- {
- register int num_acc = 0;
- while(strlen(account[num_acc].name)>0)
- {
- printf("\nCode : %.0f \n" ,account[num_acc].code);
- printf("Name : %s \n" ,account[num_acc].name);
- printf("Income: : %.2f \n" ,account[num_acc].income);
- printf("Pens : %.2f \n" ,account[num_acc].nPen);
- printf("Ins : %.2f \n" ,account[num_acc].nIns);
- printf("Depend : %.2f \n" ,account[num_acc].nDependant*1600);
- printf("Charity : %.2f \n\n" ,account[num_acc].nGift);
- printf("Taxable : %.2f \n\n" ,account[num_acc].taxable);
- printf("Tax : %.2f \n\n" ,account[num_acc].tax);
- printf("Net : %.2f \n\n" ,account[num_acc].income-account[num_acc].tax);
- num_acc++;
- }
- }
- void acc_search(float n)
- {
- for(int i=0;i<=10;i++)
- {
- if(account[i].code==n)
- {
- printf("\nCode : %.0f \n" ,account[i].code);
- printf("Name : %s \n" ,account[i].name);
- printf("Income: : %.2f \n" ,account[i].income);
- printf("Pens : %.2f \n" ,account[i].nPen);
- printf("Ins : %.2f \n" ,account[i].nIns);
- printf("Depend : %.2f \n" ,account[i].nDependant*1600);
- printf("Charity : %.2f \n\n" ,account[i].nGift);
- printf("Taxable : %.2f \n\n" ,account[i].taxable);
- printf("Tax : %.2f \n\n" ,account[i].tax);
- printf("Net : %.2f \n\n" ,account[i].income-account[i].tax);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement