Thread: Wages Calculation Program

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    9

    Wages Calculation Program

    Code:
    #include<iostream>
    
    using std::cout;
    using std::cin;
    using std::endl;
    
    int main()
    {
    
      int hoursWorked;
      double hourlyWage;
      double salary;
      double overtime;
    
    
      do {
    
        cout << "\nEnter hours worked (-1 to End): ";
        cin >> hoursWorked;
    
      if (hoursWorked == -1)
      break;
    
        cout << "Enter the employees hourly wage: ";
        cin >> hourlyWage;
    
        if (hoursWorked>40){
        overtime = (hoursWorked-40)*1.5;
        salary = ((hourlyWage * hoursWorked) + (overtime * hourlyWage));
        }
        else
        salary = (hourlyWage*hoursWorked);
    
        cout << "Salary is: " << salary;
    
        } while (hoursWorked != -1);
    
        return 0;
      }
    The program needs to calculate any hours worked over 40 as overtime (time and a half), for example 1 hour over time = 1.5 hours * hourlywage. 2 hours overtime = 3 hours * hourlywage, 3 hours overtime = 4.5 hours * hourlywage. This only applies to any hours worked OVER 40. If the total hours is 40 or below, the wage is payed at the usual hourly rate = hourlywage * hoursworked.



    Should output:
    ----------------
    Enter Hours Worked (-1 to End) : 39
    Enter the employees hourly wage: 10
    Salary is 390

    Enter hours worked (-1 to end): 41
    Enter the employees hourly wage: 10
    Salary is 415

    Outputs:
    ---------------
    Enter hours worked (-1 to End): 39
    Enter the employees hourly wage: 10
    Salary is: 390
    Enter hours worked (-1 to End): 41
    Enter the employees hourly wage: 10
    Salary is: 425


    Why do I get 425 instead of 415, as shown above?

  2. #2
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    According to your code it is suppose to give 425(410+15)

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    16
    try:
    Code:
    if (hoursWorked>40){
         overtime = (hoursWorked-40)*1.5;
         hoursWorked = 40; // need to set this here, 
         salary = ((hourlyWage * hoursWorked) + (overtime * hourlyWage));
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM