Retrieving information from a loop

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.


#include <iostream>
#include <string>

using namespace std;

const float OVERTIME = 1.5 ; //Overtime pay
const float TAX = .03625 ; //Tax rate

//function prototypes

int payroll(string);


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 <<"Employee Name: \n" << name << endl;
cout <<"Gross Pay: \n" << "$ "<< gross << endl;
cout <<"Net Pay: \n" << "$ "<< net;


cout << endl << endl << endl;

cout<<"The total gross for all employees is: " << endl;
cout << totalGross << endl;
cout<<"The total net for all employees is: " << endl;
cout << totalNet << endl;

if (count > 0)
{
avgNet = totalNet / count;
avgGross = totalGross / count;

cout <<"Average Gross Pay: "<< endl;
cout << avgGross << endl;
cout <<"Average Net Pay : " << endl;
cout << avgNet << endl;

}

return 0;

}
Last edited on
1
2
3
4
5
6
7
8
9
10
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.
For the love of chicken salad... please use code tags! :)
I LOVE Chicken Salad...back to programming -.-
Topic archived. No new replies allowed.