#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
usingnamespace std;
//**********//
int main() {
constint empId = 7; //Number of employees
int workers[empId] = {5658846, 4520125, 7895122,
8777541, 8451277, 1302850,
7580489}; //Employee ID numbers
int hours[empId]; //Holds hours worked
double payRate[empId]; //Holds pay rates
//Input the hours worked and the hourly pay rate.
cout << "Please enter the hours worked by " << empId
<< " employees and their\n"
<< "hourly pay rates.\n";
for (int index = 0; index < empId; index++)
{
cout << "Please enter the hours worked by employee number " << (index+1) << ": ";
cin >> hours[index];
cout << "Please enter the pay rate for employee number " << (index+1) << ": ";
cin >> payRate[index];
}
cout << "This is the gross pay for each employee:\n";
cout << fixed << showpoint << setprecision(2);
for (int index = 0; index < empId; index++)
{
double grossPay = hours[index] * payRate[index];
cout << "Employee #" << (index + 1);
cout << ": earned $" << grossPay << endl << endl;
}
return 0;
}
How do I get it to show the individual numbers in empId when requesting the hours worked and the hourly wage? Also, how would I make it display their ID numbers with their total wage earnings at the end? And how do I get it not to accept negative numbers for hours or a hourly wage less than $6.00?
How do I get it to show the individual numbers in empId when requesting the hours worked and the hourly wage?
You just need to loop through each element in the "workers" array using workers[index].
1 2 3 4 5 6 7 8
for (int index = 0; index < empId; index++)
{
cout << "Please enter the hours worked by employee number " << (index+1) << " (ID = " << workers[index] << ") : ";
cin >> hours[index];
cout << "Please enter the pay rate for employee number "<< (index+1) << " (ID = " << workers[index] << ") : ";
cin >> payRate[index];
}
Also, how would I make it display their ID numbers with their total wage earnings at the end?
Same thing as above.
And how do I get it not to accept negative numbers for hours or a hourly wage less than $6.00?
You would need some sort of loop to repeat until the user enters the correct response.