Compute the full overtime pay possibilities, using if statement - C++ Statement

C++ examples for Statement:if

Description

Compute the full overtime pay possibilities, using if statement

Demo Code

#include <iostream>
using namespace std;
#include <stdio.h>
int main()/*  ww w.  j  av a 2  s  .  c o m*/
{
   int hours;
   float dt, ht, rp, rate, pay;
   cout << "\n\nHow many hours were worked? ";
   cin >> hours;
   cout << "\nWhat is the regular hourly pay? ";
   cin >> rate;

   if (hours > 50)
   {
      dt = 2.0 * rate * (float)(hours - 50);
      ht = 1.5 * rate * 10.0;
   }
   else
   {
      dt = 0.0;
   }
   if (hours > 40)
   {
      ht = 1.5 * rate * (float)(hours - 40);
   }
   // Regular Pay
   if (hours >= 40)
   {
      rp = 40 * rate;
   }
   else
   {
      rp = (float)hours * rate;
   }
   pay = dt + ht + rp;   // Add three components of payroll.
   printf("\nThe pay is %.2f", pay);
   return 0;
}

Result


Related Tutorials