Advertisement
EricJohnson

Pay_Roll

Mar 12th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.64 KB | None | 0 0
  1. //Eric Johnson
  2. //Payroll Calculator
  3. //03-08-12
  4. //Mr. Searing
  5. //SUPA Computer Engineering
  6.  
  7. #include <iostream.h>
  8. #include <iomanip.h>
  9. #include <conio.h>
  10. using namespace std;
  11.  
  12. void intvalid (int* data) {  //This is really ugly if implemented inside the code
  13. while(cin.fail()) { //Input validation loop
  14.    cin.clear();  //Clear flags
  15.    cin.ignore();  //Clear input buffer
  16.    cout<<"Invalid Input - Please input a number:";
  17.    cin>>(*data);
  18.    }
  19. }
  20.  
  21. void flvalid (float* data) {  //For floats
  22. while(cin.fail()) { //Input validation loop
  23.    cin.clear();  //Clear flags
  24.    cin.ignore();  //Clear input buffer
  25.    cout<<"Invalid Input - Please input a number:";
  26.    cin>>(*data);
  27.    }
  28. }
  29.  
  30. int main()
  31. {
  32. float wage;
  33. int hours;
  34. char employee, response;
  35. cout << fixed << setprecision (2); //Set output format and precision
  36. do {
  37.    do {
  38.       clrscr();
  39.       cout << "Employee position?" <<endl;
  40.       cout << "m - Manager\n" << "h - Hourly Worker\n" << "c - Commission Worker\n" << "p - Pieceworker" <<endl;
  41.       cout << "Input:";
  42.       cin >> employee;
  43.       clrscr();
  44.       //end of dowhile
  45.       } while ((employee!='m')&&(employee!='M')&&(employee!='h')&&(employee!='H')&&(employee!='c')&&(employee!='C')&&(employee!='p')&&(employee!='P')); //Wait for valid input
  46.  
  47.    switch (employee) {  //Employee Switch
  48.  
  49.   case 'M':
  50.   case 'm':
  51.            clrscr();
  52.            cout << "How many hours did you work this week? ";
  53.            cin >> hours;
  54.            intvalid(&hours);
  55.            cout << "What is weekly wage? ";
  56.            cin >> wage;
  57.            flvalid(&wage);
  58.            if (hours >=35)
  59.            {cout << "This is your pay for the week: $" << hours * wage << endl;}
  60.            else
  61.            {cout << "this is your pay for the week: $" << (float(hours)/35)*wage << endl;}
  62.            break;
  63.  
  64.   case 'H':
  65.   case 'h':
  66.            clrscr();
  67.            cout << "Please input the number of hours worked this week: ";
  68.            cin >> hours;
  69.            intvalid(&hours);
  70.            cout << "please input your hourly wage: ";
  71.            cin >> wage;
  72.            flvalid(&wage);
  73.            if (hours > 40)
  74.            {cout << "This is your weekly pay: $" << (40 * wage) + ((hours - 40)*wage*1.5) << endl;}
  75.            else
  76.            {cout << "This is your weekly wage: $" << hours*wage << endl;}
  77.            break;
  78.  
  79.   case 'C':
  80.   case 'c':
  81.            clrscr();
  82.            cout << "Please input your gross sales for the week: ";
  83.            cin >> wage;
  84.            flvalid(&wage);
  85.            cout << "This is your pay for the week: $" << (wage*.057) + 250 << endl;
  86.            break;
  87.  
  88.   case 'P':
  89.   case 'p':
  90.            clrscr();
  91.            cout << "Please input the number of widgets assembled this week: ";
  92.            cin >> hours;
  93.            intvalid(&hours);
  94.            wage += (float(hours) * 1.5);
  95.            cout << "Please input the number of bearings assembled this week: ";
  96.            cin >> hours;
  97.            intvalid(&hours);
  98.            wage += (hours * 2);
  99.            cout << "Please input the number of transfer racks assembled this week: ";
  100.            cin >> hours;
  101.            intvalid(&hours);
  102.            clrscr();
  103.            wage += (float(hours) * 2.5);
  104.            cout << "This is your total pay for the week: $" << wage << endl;
  105.            break;
  106.            
  107. }          //end of switch
  108. do {
  109.       clrscr();
  110.       cout << "Run again?(y/n)";
  111.       cin >> response;
  112. //      end of 2 do while
  113.       } while ((response!='y')&&(response!='Y')&&(response!='n')&&(response!='N'));  //Wait for valid input
  114. //end of 3 do while
  115.    } while ((response=='y')||(response=='Y'));
  116.  
  117. }
  118. }                  //end of main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement