// 3/27/14 class example // Payroll Program #include #include using namespace std; int main() { const int NUMEMPS=11; // allow for 10 employees and extra spot for -1 double pay[NUMEMPS], hours[NUMEMPS], rate[NUMEMPS]; int idnum[NUMEMPS]; // initialize a count and a running sum int count=0, sum=0; // process a single employee // Structured Read Loop cout << "Enter an id number of an employee, -1 to finish: "; cin >> idnum[count]; while (idnum[count]!=-1 && count < NUMEMPS) { cout << "Enter hours and rate: "; cin >> hours[count] >> rate[count]; pay[count] = hours[count] * rate[count]; cout << "Employee " << idnum[count] << " worked " << hours[count] << " hours at " << rate[count] << " per hour. Pay is $" << setprecision(2) << fixed << pay[count] << '.' << endl; sum+=pay[count]; count++; // prompt and read at the end of the while loop cout << "Enter an id number of an employee, -1 to finish: "; cin >> idnum[count]; } cout << "You processed " << count << " employees." << endl; cout << "The total pay is: " << sum << '.' << endl; // At this point the program still has access to all the data in the arrays. return 0; }