bsc

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

lucproblem005.c (1578B)


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