#include <stdio.h>#include <stdlib.h>#include <string.h>//include this header for functions strcmp and strncmp struct employee{ char nameCategory[15]; double salary; double tax;};//main functionint main(){ //struct employee struct employee _employee; //prompt user to enter name category printf("Enter name category: "); //read name category scanf("%s",&_employee.nameCategory); //prompt user to enter salary printf("Enter salary: "); //read salary scanf("%lf",&_employee.salary); //calculate A 10% OF SALARY if(strcmp(_employee.nameCategory,"A")==0){ _employee.tax=0.1*_employee.salary; } //calculate B 15% OF SALARY else if(strcmp(_employee.nameCategory,"B")==0){ _employee.tax=0.15*_employee.salary; } //calculate C 20% OF SALARY else if(strcmp(_employee.nameCategory,"C")==0){ _employee.tax=0.2*_employee.salary; } //calculate OTHERS 30% OF SALARY else{ _employee.tax=0.3*_employee.salary; } //show result printf("The tax = $ %lf",_employee.tax); system("pause"); return 0;}
Comments