problems using zzzzzz as sentinel

I am having problems using a value of zzzzzz as a sentinel. Here is my assignment:

"Write a program to process weekly employee time cards for all employees of an organization. Each employee will have three data items: the employee's name, the hourly wage rate, and the number of hours worked during a given week. Employees are to be paid time-and-a-half for all hours worked over 40. A tax amount of 3.625 percent of gross salary will be deducted. The program output should show each employee's name, gross pay, and net pay, and should also display the total net and gross amounts and their averages. Use zzzzzz as a sentinel value for name."

I have used sentinel values as int before but not char. I have looked all over the place for answers on this but no luck so far. Can someone point me in the right direction? Here is my code so far. The loop works i just can't get it to end.

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
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <iomanip>
using namespace std;


int main()
{
double grosspay, hourlywage, netpay, hoursperweek, overtimepay, overtimehourlywage, overtimehours;
char  EmployeeName[20];
cout << setprecision(2) << fixed <<'\n';
cout <<"Assignment 17 by " << endl << endl;
cout << "When done, enter zzzzzz to stop." << endl;
	while (EmployeeName != "zzzzzz"){
		cout << "Please enter employee name: ";
		cin >> EmployeeName;
		cout <<"Enter hourly wage: ";
		cin >> hourlywage;
		cout <<"Enter hours worked for the current week: ";
		cin >> hoursperweek;

		if (hoursperweek <= 40)
		{
			grosspay = hoursperweek*hourlywage;
		}
		if (hoursperweek > 40)
		{
			overtimehourlywage = 1.5 * hourlywage;
			overtimepay = (hoursperweek - 40) * overtimehourlywage;
			overtimehours = hoursperweek - 40;
			grosspay = ((hoursperweek - overtimehours) * hourlywage) + overtimepay;
		}
			netpay = grosspay - (grosspay * .03625);
			cout << "Employee Name: " << EmployeeName << endl;
			cout << "Gross pay is : $" << grosspay << endl;
			cout << "Net pay is : $" << netpay << endl;
	}


	
	return 0;
}
Last edited on
You can't use != with char arrays. Use strings instead:

1
2
3
4
5
6
7
8
9
10
#include <string>

//...

// char  EmployeeName[20];  // char array, blech
string EmployeeName;  // string, much better

//...

while (EmployeeName != "zzzzzz"){  // now this will work 
Thanks!
Topic archived. No new replies allowed.