while loop?

Im trying to make a while loop but im not sure on how to do it. In the program I need to ask the user how many employees payroll they need to calculate and use a while loop to validate that the number of employees entered is 5 or less and use this number of employees inside of a for loop to run the program that many times. (Display the number each time you run the loop as "Employee #1", etc.)

[Code]
#include <iostream>
using namespace std;

int main()
{
double x,y,taxrate,grosspay,tax,netpay;

cout << "enter hours worked ";
cin >> x;

cout << "enter hourly rate ";
cin >> y;

grosspay=x*y;

if (2000 <= grosspay && grosspay < 2500)
taxrate=.45;
else if(1500<=grosspay && grosspay < 2000)
taxrate=.40;
else if (1000<= grosspay && grosspay <1500)
taxrate=.35;
else if(grosspay==1000)
taxrate=.30;
else if(0<=grosspay && grosspay <1000)
taxrate=.30;

tax=grosspay*taxrate;
netpay=grosspay-tax;

cout << "Hours worked: " << x << endl;
cout << "hourly rate:" << y << endl;
cout << "tax rate:" << taxrate << endl;
cout << "gross pay:" << grosspay << endl;
cout << "net pay:" << netpay << endl;

system("pause");
}
[/code]
Something like?:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main()
{
	int variable = 0;

	std::cin >> variable;

	while( variable < 5 )
	{
		// do stuff

		// increment the variable, else
		// it will be an infinite loop
		++variable;
	}

	return 0;
}
Nope, more like this:
1
2
3
4
5
do
{
    unsigned int Employees;
    cin >> Employees;
}while(Employees > 5);
Context clues utilized in generating this solution:
kingsamuraix wrote:
and use a while loop to validate that the number of employees entered is 5 or less
Last edited on
Topic archived. No new replies allowed.