Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Eric Johnson
- //Payroll Calculator
- //03-08-12
- //Mr. Searing
- //SUPA Computer Engineering
- #include <iostream.h>
- #include <iomanip.h>
- #include <conio.h>
- using namespace std;
- void intvalid (int* data) { //This is really ugly if implemented inside the code
- while(cin.fail()) { //Input validation loop
- cin.clear(); //Clear flags
- cin.ignore(); //Clear input buffer
- cout<<"Invalid Input - Please input a number:";
- cin>>(*data);
- }
- }
- void flvalid (float* data) { //For floats
- while(cin.fail()) { //Input validation loop
- cin.clear(); //Clear flags
- cin.ignore(); //Clear input buffer
- cout<<"Invalid Input - Please input a number:";
- cin>>(*data);
- }
- }
- int main()
- {
- float wage;
- int hours;
- char employee, response;
- cout << fixed << setprecision (2); //Set output format and precision
- do {
- do {
- clrscr();
- cout << "Employee position?" <<endl;
- cout << "m - Manager\n" << "h - Hourly Worker\n" << "c - Commission Worker\n" << "p - Pieceworker" <<endl;
- cout << "Input:";
- cin >> employee;
- clrscr();
- //end of dowhile
- } while ((employee!='m')&&(employee!='M')&&(employee!='h')&&(employee!='H')&&(employee!='c')&&(employee!='C')&&(employee!='p')&&(employee!='P')); //Wait for valid input
- switch (employee) { //Employee Switch
- case 'M':
- case 'm':
- clrscr();
- cout << "How many hours did you work this week? ";
- cin >> hours;
- intvalid(&hours);
- cout << "What is weekly wage? ";
- cin >> wage;
- flvalid(&wage);
- if (hours >=35)
- {cout << "This is your pay for the week: $" << hours * wage << endl;}
- else
- {cout << "this is your pay for the week: $" << (float(hours)/35)*wage << endl;}
- break;
- case 'H':
- case 'h':
- clrscr();
- cout << "Please input the number of hours worked this week: ";
- cin >> hours;
- intvalid(&hours);
- cout << "please input your hourly wage: ";
- cin >> wage;
- flvalid(&wage);
- if (hours > 40)
- {cout << "This is your weekly pay: $" << (40 * wage) + ((hours - 40)*wage*1.5) << endl;}
- else
- {cout << "This is your weekly wage: $" << hours*wage << endl;}
- break;
- case 'C':
- case 'c':
- clrscr();
- cout << "Please input your gross sales for the week: ";
- cin >> wage;
- flvalid(&wage);
- cout << "This is your pay for the week: $" << (wage*.057) + 250 << endl;
- break;
- case 'P':
- case 'p':
- clrscr();
- cout << "Please input the number of widgets assembled this week: ";
- cin >> hours;
- intvalid(&hours);
- wage += (float(hours) * 1.5);
- cout << "Please input the number of bearings assembled this week: ";
- cin >> hours;
- intvalid(&hours);
- wage += (hours * 2);
- cout << "Please input the number of transfer racks assembled this week: ";
- cin >> hours;
- intvalid(&hours);
- clrscr();
- wage += (float(hours) * 2.5);
- cout << "This is your total pay for the week: $" << wage << endl;
- break;
- } //end of switch
- do {
- clrscr();
- cout << "Run again?(y/n)";
- cin >> response;
- // end of 2 do while
- } while ((response!='y')&&(response!='Y')&&(response!='n')&&(response!='N')); //Wait for valid input
- //end of 3 do while
- } while ((response=='y')||(response=='Y'));
- }
- } //end of main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement