Array program doesn't run correctly.

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
42
43
44
45
46
47
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	const int NUM_EMPLOYEES = 7; // Constant int for employee amount.
	const int STRING_SIZE = 8;   // Constant int for string size. 
	int hours[NUM_EMPLOYEES];    // Int hours, because it's an integer.
	int payRate[NUM_EMPLOYEES];  // Int payRate, because it's an integer.
	float wages[NUM_EMPLOYEES];  // Float wages, because it can be a decimal.
					
	cout << "Enter the requested information for each employee. " << endl;
	cout << endl;
		
		// Array with the 7 employee identification numbers.
		char empId[NUM_EMPLOYEES][STRING_SIZE] = 
					{ "5658845", "4520125", "7895122", "8777541",
					  "8451277", "1302850", "7580489" };
for ( int count = 0; count < NUM_EMPLOYEES; count++ )
		{
		cout << "Employee #" << empId[count] << endl;
		cout << '\t' << "Hours worked: " << " ";	 
		cin >> hours[count];
		while( hours[count] < 0 ) // Hours worked must be at least 0.
			{
				// Error message.
				cout << "Hours worked must be 0 or more. Please re-enter: " << "";
				cin >> hours[count];
			}
		cout << '\t' << "Pay rate: $" << " ";
		cin >> payRate[count];
		while( payRate[count] < 6 ) // Pay rate must be at least $6.
			{ 
				// Error message.
				cout << "Pay rate must be $6.00 or more. Please re-enter: $" << "";
				cin >> payRate[count];
			}
		wages[count] = hours[count] * payRate[count]; // Calculates employees wages.
			
			cout << "----------------------------" << endl;
			cout << "Employee" << '\t' << "Wages" << endl;
			cout << "----------------------------" << endl;
			cout << "Employee #" << empId[count] << " " << "$  " << wages[count] << endl;
		}
	return 0;
}


There is my code. It displays the employees # and wage after each employee, but I only want it to do it once after all 7 employee's info is entered. I move the chart outside the loop and I get an error for empId[count].
I don't understand your meaning clearly. I edited your code.
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	const int NUM_EMPLOYEES = 7; // Constant int for employee amount.
	const int STRING_SIZE = 8;   // Constant int for string size. 
	int hours[NUM_EMPLOYEES];    // Int hours, because it's an integer.
	int payRate[NUM_EMPLOYEES];  // Int payRate, because it's an integer.
	float wages[NUM_EMPLOYEES];  // Float wages, because it can be a decimal.
	
	cout << "Enter the requested information for each employee. " << endl;
	cout << endl;
	
	// Array with the 7 employee identification numbers.
	char empId[NUM_EMPLOYEES][STRING_SIZE] = 
	{ "5658845", "4520125", "7895122", "8777541",
		"8451277", "1302850", "7580489" };
	for ( int count = 0; count < NUM_EMPLOYEES; count++ )
	{
		cout << "Employee #" << empId[count] << endl;
		cout << '\t' << "Hours worked: " << " ";	 
		cin >> hours[count];
		while( hours[count] < 0 ) // Hours worked must be at least 0.
		{
			// Error message.
			cout << "Hours worked must be 0 or more. Please re-enter: " << "";
			cin >> hours[count];
		}
		cout << '\t' << "Pay rate: $" << " ";
		cin >> payRate[count];
		while( payRate[count] < 6 ) // Pay rate must be at least $6.
		{ 
			// Error message.
			cout << "Pay rate must be $6.00 or more. Please re-enter: $" << "";
			cin >> payRate[count];
		}
		wages[count] = hours[count] * payRate[count]; // Calculates employees wages.
		
		/*cout << "----------------------------" << endl;
		cout << "Employee" << '\t' << "Wages" << endl;
		cout << "----------------------------" << endl;
		cout << "Employee #" << empId[count] << " " << "$  " << wages[count] << endl;*/
	}
	
	cout<<"----------------------------"<<endl
		<<"Employee"<<'\t'<<"Wages"<<endl
		<<"----------------------------"<< endl;
	for( int i = 0; i < NUM_EMPLOYEES; i++ )
	{
		cout<<"Employee #"<< empId[i]<<" "<< "$  "<<wages[i]<<endl;
	}
	
	return 0;
}
Topic archived. No new replies allowed.