Payroll Program Help Needed (Loop)

Hello, my assignment for my Intro to C++ and OOP class is that I need to be able to make a payroll system that loops and allows the user to input the amount of employees that will be repeated. Here's what I have:

#include <iostream.h>
main(){
int numberofemployees;
int employeeid, hoursworked;
float hourlyrate, grosspay, taxamount, netpay;
const float TAXRATE = 0.20;
numberofemployees = 0;
while( numberofemployees < 5 ){
cout << " ENTER THE EMPLOYEE ID:";
cin>>employeeid;
cout << "ENTER THE HOURS WORKED:";
cin>>hoursworked;
cout << "ENTER THE HOURLY RATE:";
cin>>hourlyrate;
grosspay = hoursworked * hourlyrate;
taxamount = grosspay * TAXRATE;
netpay = grosspay - taxamount;
cout << "EMPLOYEE ID IS"<<employeeid << endl;
cout << "YOUR GROSSPAY IS"<<grosspay << endl;
cout << "YOUR TAX AMOUNT IS"<<taxamount<<endl;
cout << "YOUR NETPAY IS"<<netpay<<endl<<endl;
numberofemployees = numberofemployees + 1;
}//WHILE
system("PAUSE");
return 0;
}//MAIN

Now I just need to add in an option that allows the user to repeat the amount of employees they specify. I believe this is an interactive loop so when you execute the program the first question isn't the employee ID but the amount of employees that will be repeated: "How many employees would you like to enter?"

Whoever can help me with this I would really appreciate it
I suggest using a for loop after you ask how many employees the person would like to enter, another way to do it is by checking the employee ID, a lot of people like to use if statements to check to see if the ID is 0 or less and then break the loop that way. Using your example, the for loop would be a better implementation.

Also, you need to include the line using namespace std; at the top of your program before main and after your preprocessor directive.
I hate to say it, but this is my first programming course I've ever taken at college and I'm still a little confused about your replay although I appreciate you taking the time to do so. I don't know how to create the input that asks, "How Many Employees Would You Like To Enter?" Pretty much I'm trying to figure out what needs to be added so my program understands the amount of employees the user specifies. I apologize if I don't understand you clearly, but I've only been programming for 2 weeks now. Would you be able to copy my program and add in what your talking about for an example?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream.h>
int main()  //main() should return type int
{ 
   int numberofemployees;
   int employeeid, hoursworked;
   float hourlyrate, grosspay, taxamount, netpay;
   const float TAXRATE = 0.20;
   numberofemployees = 0;
   while( numberofemployees < 5 )
   {
      cout << " ENTER THE EMPLOYEE ID:";
      cin>>employeeid;
      cout << "ENTER THE HOURS WORKED:";
      cin>>hoursworked;
      cout << "ENTER THE HOURLY RATE:";
      cin>>hourlyrate;
      grosspay = hoursworked * hourlyrate;
      taxamount = grosspay * TAXRATE;
      netpay = grosspay - taxamount;

      cout << "EMPLOYEE ID IS"<<employeeid << endl;
      cout << "YOUR GROSSPAY IS"<<grosspay << endl;
      cout << "YOUR TAX AMOUNT IS"<<taxamount<<endl;
      cout << "YOUR NETPAY IS"<<netpay<<endl<<endl;
      numberofemployees = numberofemployees + 1;
      }//WHILE
   system("PAUSE");
   return 0;
}//MAIN


On my line 9, the while loop is set to repeat while numberofemployees is less than 5, but it can be any number you want it to be. What if you declared a variable, say 'n', and prompted a user to enter the number of employees they want to process. You could than assign that number to 'n' and use it the while loop
Yeah that's what I need to do. I need to allow the user to specify how many employees they would like to enter before-hand. So I would use the variable "n" correct? So when the program executes the first question will be how many employees would you like to enter. I understand how to do "while( numberofemployees < 5 )" but I need to have a 4th cout within the while asking the question for the user to input. That's where I'm stuck. I appreciate all of your help too by the way. If you could lastly explain that I would be able to finish my assignment
It would look something like:
[code]int numberOfEmployees;

cout << "How many employees would you like to enter? ";
cin >> numberOfEmployees;

for(int i = 0; i < numberOfEmployees; i ++) {
// Put all the code in here for looping input
// You can also use (i + 1) to inform the user which employee
// they're currently entering information for.
}
I am going to try that today. Thank you for taking the time to explain this to me. If I have any problems I'll reply back but I appreciate the help!
I just did what you said and I'm having an error because it's not executing. Would you be able to input that code you showed me into my program so I can make sure I put everything in the right order? It would be a great help and would show me exactly how it needs to be done. I feel once I see it properly I will have the knowledge to do it on my own for now on. I think maybe I put something in the wrong spot.
This is what I have with errors:

#include <iostream.h>
main(){
int numberofemployees;
int employeeid, hoursworked;
float hourlyrate, grosspay, taxamount, netpay;
const float TAXRATE = 0.20;
for(int i = 0; i < numberOfEmployees; i ++) {
cout << "How many employees would you like to enter? ";
cin >> numberOfEmployees;
cout << " ENTER THE EMPLOYEE ID:";
cin>>employeeid;
cout << "ENTER THE HOURS WORKED:";
cin>>hoursworked;
cout << "ENTER THE HOURLY RATE:";
cin>>hourlyrate;
grosspay = hoursworked * hourlyrate;
taxamount = grosspay * TAXRATE;
netpay = grosspay - taxamount;
cout << "EMPLOYEE ID IS"<<employeeid << endl;
cout << "YOUR GROSSPAY IS"<<grosspay << endl;
cout << "YOUR TAX AMOUNT IS"<<taxamount<<endl;
cout << "YOUR NETPAY IS"<<netpay<<endl<<endl;
numberofemployees = numberofemployees + 1;
}//WHILE
system("PAUSE");
return 0;
}//MAIN
Topic archived. No new replies allowed.