1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include <iostream>
#include <iomanip> // for 'fixed' and 'setprecision'
#include <cctype> // for toupper
using namespace std;
int main()// function main begins program execution
{
char paycode;
int TotalHours,
TotalPay,
sales;
double pay,
HourlyPay,
SalesComm,
WeeklySalary,
WeeklyPay,
PayPerWidget,
WidgetsSold,
GrossWeeklySales;
cout << "[M]anager\n"
<< "[H]ourly Worker\n"
<< "[C]ommission Worker\n"
<< "[W]idget Worker\n"
<< "[Q]uit\n"
<< "Enter paycode: ";
cin >> paycode;
if (isalpha(paycode)){ // make sure paycode is a letter
paycode = toupper(paycode); // make paycode caps
}else{
cout << "Not a valid letter.\n";
}
cout << fixed << showpoint << setprecision(2);
switch (paycode)
{
case 'M':
cout << "Manager selected." << endl;
cout << "Enter weekly salary: ";
cin >> WeeklySalary;
cout << endl;
pay = WeeklySalary;
cout << "Managers pay is $" << pay;
cout << endl;
break;
case 'H':
cout << "Hourly Worker selected." << endl;
cout << "Enter the hourly pay:";
cin >> HourlyPay;
cout << endl;
cout << "Enter the total hours worked:";
cin >> TotalHours;
if (TotalHours <= 40)
pay = HourlyPay * TotalHours;
else
pay = (40 * HourlyPay) + (TotalHours - 40) * (HourlyPay * 1.5);
cout << endl;
cout << "Hourly Worker's pay is $" << pay;
cout << endl;
break;
case 'C':
cout << "Commission Worker selected." << endl;
cout << "Enter weekly salary:";
cin >> WeeklyPay;
cout << endl;
cout << "Enter commission (%): ";
cin >> SalesComm;
cout << endl;
cout << "Enter gross weekly sales:";
cin >> GrossWeeklySales;
cout << endl;
pay = (SalesComm / 100) * GrossWeeklySales + WeeklyPay;
cout << " Commission Worker's pay is $" << pay;
cout << endl;
break;
case 'W':
cout << "Widget Worker selected." << endl;
cout << "Enter pay per widget:";
cin >> PayPerWidget;
cout << endl;
cout << "Enter number of widgets: ";
cin >> WidgetsSold;
cout << endl;
pay = PayPerWidget * WidgetsSold;
cout << "Widget Worker's pay is $" << pay;
cout << endl;
break;
case 'Q':
cout << "Good-bye!\n";
break;
default:
cout << "Sorry, character was not M, H, C, W, or Q.\n"
<< "Terminating program!\n";
break;
}
return 0;
}
|
[M]anager
[H]ourly Worker
[C]ommission Worker
[W]idget Worker
[Q]uit
Enter paycode: d
Sorry, character was not M, H, C, W, or Q.
Terminating program!
[M]anager
[H]ourly Worker
[C]ommission Worker
[W]idget Worker
[Q]uit
Enter paycode: m
Manager selected.
Enter weekly salary:
|