Okay i've gotten this program to run almost perfectly the first time I compiled it, so I'm pretty happy about that. What the program is supposed to do is use a loop statement to calculate payroll for employees, the sentinel value obviously is ZZZZZ, i've got everything down but now I can't figure out how to retrieve each individual employees information. Can someone point me in the right direction, here is the code.
int main()
{
string name; //employee name
string program;
cout << "This program will calculate payroll" << endl;
cout << "for your entire business" << endl;
cout << "enter employee name, and then all information as prompted," << endl;
cout << "after last employee entered type ZZZZZ to display results."<< endl;
cout << "Enter first employees name now:" << endl;
cin >> name;
program = payroll(name);
return 0;
}
int payroll(string name)
{
// Local Variables
float payRate; // employee payrate
float hoursWorked; // hours worked
float gross; // gross pay
float net; // net pay after deductions
float totalNet; // total net for all employees
float totalGross; // total gross for all employees
float avgNet; // average net for all employees
float avgGross; // average gross for all employees
const string SENTINEL = "ZZZZZ"; //Loop exit string
float otPay;
int count;
name;
count = 0;
totalNet = 0;
totalGross = 0;
while (name != SENTINEL) // Start of Loop
{
cout << "What is your current payrate:" << endl;
cin >> payRate;
cout << "How many hours were worked this past period" << endl;
cin >> hoursWorked;
{
if (hoursWorked > 40)
{
otPay = (hoursWorked - 40) * payRate * OVERTIME;
gross = (hoursWorked - (hoursWorked - 40)) * payRate + otPay;
}
else
gross = hoursWorked * payRate;
}
totalGross += gross; //calculate total gross
net = gross - (gross * TAX); //net pay
totalNet += net; //calculate total net
count++; // counter for averages
cout <<"Enter next employee name: \n";
cin >> name;
cout<<"The total gross for all employees is: " << endl;
cout << totalGross << endl;
cout<<"The total net for all employees is: " << endl;
cout << totalNet << endl;
do {
cout << "This program will calculate payroll" << endl;
cout << "for your entire business" << endl;
cout << "enter employee name, and then all information as prompted," << endl;
cout << "after last employee entered type ZZZZZ to display results."<< endl;
cout << "Enter first employees name now:" << endl;
cin >> name;
program = payroll(name);
} while (name != "ZZZZZ");
That should handle your loop.
As for being able to enter multiple employees and being able to access them afterwards, you might want to consider an array.