bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / letusc / lucproblem005.c

lucproblem005.c (1442B)


      1 /* Write a program to calculate overtime pay of 10 employees. Overtime is
      2 paid at the rate of Rs. 120.00 per hour for every hour worked above 40
      3 hours. Assume that employees do not work for fractional part of an hour. */
      4 /* ONLY WHILE LOOP ALLOWED */
      5 /* Let Us C, Chap - 5, Page - 83, Problem 5.1 */
      6 
      7 #include <stdio.h>
      8 #include <conio.h>
      9 int main()
     10 {
     11     int working_hour, i = 1;
     12     double pay;
     13     while (i <= 10)
     14     {
     15         printf("Enter the working hour for the employee no. %d : ", i);
     16         if (scanf("%d", &working_hour) != 1)
     17         {
     18             printf("\n\tPlease enter a number as woking hour.\n\n");
     19             while (getchar() != '\n')
     20                 ;
     21             // above line discard the input characters untill getchar() reaches the new line character.
     22             /* if I do not discard the input, after 'continue;' statement that input will be again taken 
     23             by scanf (In the line 17). It will be a infinite loop of error. */
     24             continue;
     25         }
     26         // checking overtime
     27         if (working_hour > 40)
     28         {
     29             pay = (working_hour - 40) * 120.00;
     30             printf("\n\tOvertime working hours of Employee %d : %d", i, (working_hour - 40));
     31             printf("\n\tPay of the overtime for Employee %d   : Rs. %.2f\n\n", i, pay);
     32         }
     33         else
     34             printf("\n\tEmployee %d did not work any overtime.\n\n", i);
     35         i++; // changing to next employee
     36     }
     37 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror