/* payroll program with tax deductions - illustrate conditional assignment * illustrate redirection of cout to file */ #include #include using namespace std; int main() { int id; //employee id double hours,rate,pay,tax,netpay; int numemp = 0; //count the employees //un-comment to redirect cout to a file //ofstream cout("c:\\bc\\CISC1110\\pgms\\chapter3\\myoutput.txt"); cout.setf(ios::fixed,ios::floatfield); cout.precision(2); //set decimal precision cout << "Please enter an ID (enter -1 to stop): "; cin >> id; //read ID while (id != -1) { //check for fake ID cout << "Please enter the hours worked: "; cin >> hours; //read hours worked cout << "Please enter the rate of pay: "; cin >> rate; //read rate of pay pay = hours * rate; //calculate pay tax = (pay < 300) ? 0.15 * pay : 0.28 * pay; //calculate tax netpay = pay - tax; //calculate the net pay cout << "Employee " << id << " worked " << hours << " hours at a rate of pay of $" << rate << " earning $" << pay << endl; cout << "tax withheld was $" << tax << " leaving net pay" <<" of $" << netpay << endl << endl; numemp++; //increment counter cout << "Please enter an ID (enter -1 to stop): "; cin >> id; //read new ID } cout << "\nWe have processed " << numemp << " employees" << endl; //un-comment when redirecting cout to a file // cout.close(); //close the file // system("pause"); //un-comment when using DevC++ return 0; }