Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include <stdbool.h>
  4. #include<string.h>
  5. #include<conio.h>
  6.  
  7. bool isValidYN(char letter)
  8. {
  9. if(letter =='y'||letter == 'n')
  10. return true;
  11. else
  12. return false;
  13. }
  14.  
  15. bool isValidNumber(char * string)
  16. {
  17. for(int i = 0; i < strlen( string ); i ++)
  18. {
  19. if (string[i] < 48 || string[i] > 57)
  20. return false;
  21. }
  22. return true;
  23. }
  24.  
  25. struct acc
  26. {
  27. char name[100];
  28. float income, nGift, nDependant, tax, taxable, nPen, nIns, code, net;
  29. };
  30.  
  31. void display_options();
  32. void acc_create();
  33. void acc_display();
  34. void acc_search(float);
  35. struct acc account[20];
  36.  
  37. int num_acc;
  38.  
  39. int main()
  40. {
  41. float n;
  42. char option;
  43. num_acc=0;
  44. while(1)
  45. {
  46. display_options();
  47. printf("Enter your choice: ");
  48. option = getch();
  49. switch(option)
  50. {
  51. case '1':
  52. acc_create();
  53. break;
  54. case '2':
  55. acc_display();
  56. break;
  57. case '3':
  58. printf("\nEnter employee code to search: ");
  59. scanf("%f", &n);
  60. acc_search(n);
  61. break;
  62. default :
  63. system("cls");
  64. break;
  65. }
  66. }
  67. }
  68.  
  69. void display_options()
  70. {
  71. printf("\nChoose one of these following options: \n");
  72. printf("1. Enter a list of employee \n");
  73. printf("2. Display tax information \n");
  74. printf("3. Search an employee buy code \n");
  75. printf("0. Exit \n");
  76. }
  77.  
  78. void acc_create()
  79. {
  80. float nIncome, nGift, nDependant, nCode, nPen, nIns, tax, taxable, net;
  81. char name[50], income[50], pension, health, dependant[5], gift[50], code[5];
  82. fflush(stdin);
  83. printf("\nEnter personal information: \n");
  84. start1:
  85. printf("Enter your code: ");
  86. scanf("%s", code);
  87. if(atof(code)==0)
  88. exit(main);
  89. if(!(isValidNumber(code)))
  90. {
  91. printf("Invalid input, re-enter: \n");
  92. goto start1;
  93. }
  94. nCode=atof(code);
  95. printf("Enter your name: ");
  96. fflush(stdin);
  97. gets(name);
  98. start2:
  99. printf("Income for the current month (in thounsand VND): ");
  100. scanf("%s", &income);
  101. if(!(isValidNumber(income)))
  102. {
  103. printf("Invalid input, re-enter: \n");
  104. goto start2;
  105. }
  106. nIncome=atof(income);
  107. start3:
  108. printf("Pension contributions (5%) y/n?: ");
  109. scanf("%s", &pension);
  110. if(!(isValidYN(pension)))
  111. {
  112. printf("Invalid input, re-enter: \n");
  113. goto start3;
  114. }
  115. if(pension=='y')
  116. nPen=nIncome*0.05;
  117. else
  118. nPen=0;
  119. start4:
  120. printf("Health Insurance (1%) y/n?: ");
  121. scanf("%s", &health);
  122. if(!(isValidYN(health)))
  123. {
  124. printf("Invalid input, re-enter: \n");
  125. goto start4;
  126. }
  127. if(health=='y')
  128. nIns=nIncome*0.01;
  129. else
  130. nIns=0;
  131. start5:
  132. printf("Number of dependants < 18 years old: ");
  133. scanf("%s", &dependant);
  134. nDependant=atof(dependant);
  135. if(!(isValidNumber(dependant)))
  136. {
  137. printf("Invalid input, re-enter: \n");
  138. goto start5;
  139. }
  140. start6:
  141. printf("Gift of charity: ");
  142. scanf("%s", &gift);
  143. nGift=atof(gift);
  144. if(!(isValidNumber(gift))||nGift>nIncome)
  145. {
  146. printf("Invalid input, re-enter: \n");
  147. goto start6;
  148. }
  149. float value=nIncome-(4000+nIncome*0.05+nIncome*0.01+nDependant*1600+nGift);
  150. if(value<=5000)
  151. tax=value*0.05;
  152. if(5000<value<=10000)
  153. tax=5000*0.05+(value-5000)*0.1;
  154. if(10000<value<=20000)
  155. tax=5000*0.05+5000*0.1+(value-10000)*0.15;
  156. if(20000<value<=30000)
  157. tax=5000*0.05+5000*0.1+10000*0.15+(value-20000)*0.2;
  158. if(30000<value<=50000)
  159. tax=5000*0.05+5000*0.1+10000*0.15+10000*0.2+(value-30000)*0.25;
  160. if(50000<value<=80000)
  161. tax=5000*0.05+5000*0.1+10000*0.15+10000*0.2+20000*0.25+(value-50000)*0.3;
  162. if(80000<value)
  163. tax=5000*0.05+5000*0.1+10000*0.15+10000*0.2+20000*0.25+30000*0.3+(value-80000)*0.35;
  164. strcpy(account[num_acc].name,name);
  165. account[num_acc].code=nCode;
  166. account[num_acc].income=nIncome;
  167. account[num_acc].nPen=nPen;
  168. account[num_acc].nIns=nIns;
  169. account[num_acc].nDependant=nDependant;
  170. account[num_acc].nGift=nGift;
  171. account[num_acc].taxable=nIncome-(4000+nIncome*0.05+nIncome*0.01+nDependant*1600+nGift);
  172. account[num_acc].tax=tax;
  173. account[num_acc].net=nIncome-tax;
  174. num_acc++;
  175. }
  176.  
  177. void acc_display()
  178. {
  179. register int num_acc = 0;
  180. while(strlen(account[num_acc].name)>0)
  181. {
  182. printf("\nCode : %.0f \n" ,account[num_acc].code);
  183. printf("Name : %s \n" ,account[num_acc].name);
  184. printf("Income: : %.2f \n" ,account[num_acc].income);
  185. printf("Pens : %.2f \n" ,account[num_acc].nPen);
  186. printf("Ins : %.2f \n" ,account[num_acc].nIns);
  187. printf("Depend : %.2f \n" ,account[num_acc].nDependant*1600);
  188. printf("Charity : %.2f \n\n" ,account[num_acc].nGift);
  189. printf("Taxable : %.2f \n\n" ,account[num_acc].taxable);
  190. printf("Tax : %.2f \n\n" ,account[num_acc].tax);
  191. printf("Net : %.2f \n\n" ,account[num_acc].income-account[num_acc].tax);
  192. num_acc++;
  193. }
  194. }
  195. void acc_search(float n)
  196. {
  197. for(int i=0;i<=10;i++)
  198. {
  199. if(account[i].code==n)
  200. {
  201. printf("\nCode : %.0f \n" ,account[i].code);
  202. printf("Name : %s \n" ,account[i].name);
  203. printf("Income: : %.2f \n" ,account[i].income);
  204. printf("Pens : %.2f \n" ,account[i].nPen);
  205. printf("Ins : %.2f \n" ,account[i].nIns);
  206. printf("Depend : %.2f \n" ,account[i].nDependant*1600);
  207. printf("Charity : %.2f \n\n" ,account[i].nGift);
  208. printf("Taxable : %.2f \n\n" ,account[i].taxable);
  209. printf("Tax : %.2f \n\n" ,account[i].tax);
  210. printf("Net : %.2f \n\n" ,account[i].income-account[i].tax);
  211. break;
  212. }
  213. }
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement