LAB 5 CS 109 ProgrammingII Application of Functions Write a
Solution
#include<stdio.h>
 #include<stdlib.h>
 double NetIncome(double grossIncome, int noOfChildren, char option);
 double Tax(double netincome);
 int main() {
 double grossIncome;
 int noOfChildren;
 char option;
 /*User input for grossIncome , noOfChildren and option*/
 scanf(\"%lf\", &grossIncome);
 scanf(\" %d\", &noOfChildren);
 scanf(\" %c\", &option);
 double netincome=NetIncome(grossIncome,noOfChildren,option);
 double tax=Tax(netincome);
 /*Printing the required data*/
 printf(\"Gross income = %lf\",grossIncome);
 printf(\"\ No of Children = %d\",noOfChildren);
 if(option==\'s\' || option==\'S\') {
 printf(\"\ Option type = Single\");
 }
 else if(option==\'j\' || option==\'J\'){
 printf(\"\ Option type = Joint\");
 }
 printf(\"\ Net income = %lf\",netincome);
 printf(\"\ Tax applicable = %lf\",tax);
   
 }
 /*Function to calculate net income*/
 double NetIncome(double grossIncome, int noOfChildren, char option) {
 double netincome=0;
 double stdDeduction=0;
 int noOfExemption=0;
 /*Values set depending on the option */
 if(option==\'s\' || option==\'S\') {
 stdDeduction=8000.00;
 noOfExemption=1+noOfChildren;
 }
 else if(option==\'j\' || option==\'J\'){
 stdDeduction=12000.00;
 noOfExemption=2+noOfChildren;
 }
 /*Only s,S,j,J are allowed*/
 else {
 printf(\"Invalid option\");
 exit(0);
 }
 double dependentDeduction = noOfExemption*2500.00;
 double totalDeduction=stdDeduction+dependentDeduction;
 netincome=grossIncome-totalDeduction;
 return netincome;
 }
/*Function to calculate tax*/
 double Tax(double netincome) {
 double taxAmount=0;
 if(netincome<20000)
 taxAmount=0;
 else if(netincome>=20000 && netincome<50000)
 taxAmount=0.1*netincome;
 else if(netincome>=50000 && netincome<100000)
 taxAmount=0.15*netincome;
 else if(netincome>=100000)
 taxAmount=0.2*netincome;
 return taxAmount;
 }
 *********************************************************************
  END OF PROGRAM
 *********************************************************************
Sample Input:
 50000
 2
 j
Sample Output:
 Gross income = 50000.000000
 No of Children = 2
 Option type = Joint
 Net income = 28000.000000
 Tax applicable = 2800.000000
Sample Input:
 70000
 1
 S
Sample Output:
 Gross income = 70000.000000
 No of Children = 1
 Option type = Single
 Net income = 57000.000000
 Tax applicable = 8550.000000
Sample Input:
 70000
 1
 m
Sample Output:
 Invalid option