Advertisement
BladeMechanics

Benefits program Prog1

Jul 28th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.45 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<ctype.h> //function variable=toupper(variable)
  4. #include<stdlib.h> //function fflush(stdin) to make sure input overflow does not happen
  5.  
  6. void main()
  7. {
  8.     int hours;
  9.     float rate, benefits, gross, tax;
  10.     char plan, control;
  11.     printf("Please enter the number of hours worked: ");
  12.     scanf_s("%d", &hours);
  13.     printf("Please enter the salary rate: ");
  14.     scanf_s("%f", &rate);
  15.     fflush(stdin);
  16.     gross = (float)hours*rate;
  17.     tax = gross*.1;
  18.     printf("\nRetirement plan offers:");
  19.     printf("\nS\tStandard Retirement Plan - %.2f(5%%) deducted from gross pay", gross*.05);
  20.     printf("\nP\tPremium Retirement Plan - %.2f(8%%) deducted from gross pay", gross*.08);
  21.     printf("\nN\tNo Retirement Plan");
  22.     printf("\nPlease enter the letter of your choice: ");
  23.     fflush(stdin);
  24.     scanf_s(" %c", &plan);
  25.     plan = toupper(plan);//this changes the character value to uppercase regardless of input
  26.     if (plan == 'S') benefits = gross*.05;
  27.     else if (plan == 'P') benefits = gross*.08;
  28.     else if (plan == 'N') benefits = 0;
  29.     else
  30.     {
  31.         printf("\nInvalid entry. No retirement plan selected. Proceeding.");
  32.         benefits = 0;
  33.     }
  34.     printf("\nWould you like to add Medical insurance? (Php 1500)\nY/N :");
  35.     fflush(stdin);
  36.     scanf_s(" %c", &control);
  37.     control = toupper(control);//this changes the character value to uppercase regardless of input
  38.     if (control == 'Y') benefits = benefits + 1500;
  39.     else if (control != 'N') printf("/nInvalid entry. Benefit not added to total.");
  40.     printf("\nWould you like to add Life insurance? (Php 500)\nY/N :");
  41.     fflush(stdin);
  42.     scanf_s(" %c", &control);
  43.     control = toupper(control);//this changes the character value to uppercase regardless of input
  44.     if (control == 'Y') benefits = benefits + 500;
  45.     else if (control != 'N') printf("/nInvalid entry. Benefit not added to total.");
  46.     printf("\nWould you like to add Dental insurance? (Php 100)\nY/N :");
  47.     fflush(stdin);
  48.     scanf_s(" %c", &control);
  49.     control = toupper(control);//this changes the character value to uppercase regardless of input
  50.     if (control == 'Y') benefits = benefits + 100;
  51.     else if (control != 'N') printf("/nInvalid entry. Benefit not added to total.");
  52.     //input evaluation ends here, output next.
  53.     printf("\nGross pay:\tPhp. %0.2f", gross);
  54.     printf("\nTax deduction:\tPhp. %0.2f", tax);
  55.     printf("\nTotal benefits:\tPhp. %0.2f", benefits);
  56.     printf("\nNet pay:\tPhp. %.2f", gross - tax - benefits);
  57.     printf("\n\nPress any key to end program.");
  58.     _getch();
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement