help with arrays

I cant seem to get my output to give me the correct number for wages. All I get is a really long number that makes no sense. I really don't know what else to try and I am honestly stuck.

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 #include<iostream>
 #include<iomanip>
 using namespace std;

void getInfo();
void showInfo();

 int main()
 {
	
	
	cout <<"Welcome to the Payroll program" << endl;
	cout <<"created by " << endl << endl;
	
	
	getInfo();
	showInfo();
		
system("pause");
	return 0;
 }

 void getInfo()
 {
	  
	 const int EMP = 7;
	 int empId[EMP] = {565, 452, 789, 877, 845, 130, 758};
	 double payRate;
	 double hoursWorked;
	 double wagesEarned[EMP];

		for(int count = 0;count <= 6; count++)
		{
			 cout << "Employee number : " << empId[count] << endl;
	
			 cout << "\nEnter employee's hour : ";
			 cin >> hoursWorked;
		while (hoursWorked < 0)
		{
			cout <<"Please enter a positive number: ";
			cin >> hoursWorked;
		}
		
			 cout << "Enter employee's pay rate: ";
			 cin >> payRate;
		while (payRate < 6.00)
		{
			cout <<"Please enter a pay rate higher than $6.00: ";
			cin >> payRate;
		}
				wagesEarned[count] = hoursWorked * payRate;
			 cout << "\n";
		 }
 }


 void showInfo()
 {
	const int EMP = 7;
	int empId[EMP] = {565, 452, 789, 877, 845, 130, 758};
	double wagesEarned[EMP];
	
	
	
			 for(int count = 0;count <= 6;count++)
				{
					
					cout << "Employee number : " << empId[count] << endl;
				cout << "Employee gross wager : " << fixed << setprecision(2) <<showpoint << wagesEarned[EMP] << endl;
					cout << "\n";
				}	
 }

In this function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void showInfo()
 {
	const int EMP = 7;
	int empId[EMP] = {565, 452, 789, 877, 845, 130, 758};
	double wagesEarned[EMP];
	
	
	
			 for(int count = 0;count <= 6;count++)
				{
					
					cout << "Employee number : " << empId[count] << endl;
				cout << "Employee gross wager : " << fixed << setprecision(2) <<showpoint << wagesEarned[EMP] << endl;
					cout << "\n";
				}	
 }


you are outputting elements of array wagesEarned that was not initialized. So it contains arbitrary values.
Last edited on
so how would I initialize them??
@cshu

From the looks of it, you are trying to access a value outside the boundaries of wagesEarned[] since EMP is equal to 7, and the array would be from 0 to 6. So, this..
cout << "Employee gross wager : " << fixed << setprecision(2) <<showpoint << wagesEarned[EMP] << endl;

should look more like..
cout << "Employee gross wager : " << fixed << setprecision(2) <<showpoint << wagesEarned[count] << endl; as you have it in showing the empID[count], above it.
Since we already have const int EMP = 7;

and int empId[EMP] = {565, 452, 789, 877, 845, 130, 758};

Don't do this: for(int count = 0;count <= 6;count++)

Instead, use EMP: for( int count = 0; count < EMP; ++count )

should look more like..
cout << "Employee gross wager : " << fixed << setprecision(2) <<showpoint << wagesEarned[count] << endl; as you have it in showing the empID[count], above it.


Yeah should be like that.
As for setting these variables :

1
2
3
int EMP = 7;
int empId[EMP] = {565, 452, 789, 877,845,130,758};
double wagesEarned[EMP];


Should be global variables instead?
> Should be global variables instead?

const int EMP = 7; could be a global variable.

For the arrays, it is perhaps better to pass them to getInfo() and showInfo().

1
2
void getInfo( int empID[EMP], double wagesEarned[EMP] ) ;
void showInfo( const int empID[EMP], const double wagesEarned[EMP] ) ;
now my problem is in main, it is telling me that the functions doesn't take 0 arguments
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<iostream>
 #include<iomanip>
 using namespace std;

 const int EMP = 7;

void getInfo(int empId[EMP],double wagesEarned[EMP]);
void showInfo(const int empId[EMP], const double wagesEarned[EMP]);

 int main()
 {
	
	
	cout <<"Welcome to the Payroll program" << endl;
	cout <<"created by " << endl << endl;
	
	
	getInfo();
	showInfo();
		
system("pause");
	return 0;
 }

 void getInfo()
 {
	  
	 const int EMP = 7;
	 int empId[EMP] = {565, 452, 789, 877, 845, 130, 758};
	 double payRate;
	 double hoursWorked;
	 double wagesEarned[EMP];

		for(int count = 0;count <= 6; count++)
		{
			 cout << "Employee number : " << empId[count] << endl;
	
			 cout << "\nEnter employee's hour : ";
			 cin >> hoursWorked;
		while (hoursWorked < 0)
		{
			cout <<"Please enter a positive number: ";
			cin >> hoursWorked;
		}
		
			 cout << "Enter employee's pay rate: ";
			 cin >> payRate;
		while (payRate < 6.00)
		{
			cout <<"Please enter a pay rate higher than $6.00: ";
			cin >> payRate;
		}
				wagesEarned[count] = hoursWorked * payRate;
			 cout << "\n";
		 }
 }


 void showInfo()
 {
	const int EMP = 7;
	int empId[EMP] = {565, 452, 789, 877, 845, 130, 758};
	double wagesEarned[EMP];
	
	
	
			 for(int count = 0;count < count;count++)
				{
					
					cout << "Employee number : " << empId[count] << endl;
				cout << "Employee gross wager : " << fixed << setprecision(2) <<showpoint << wagesEarned[count] << endl;
					cout << "\n";
				}	
 }


in lines 21 and 22
Your functions at lines 25 and 59 must match the function prototypes at lines 7 and 8. Also where you call then at lines 18 and 19.
ok ive done that now my next problem is with the functions in main
getInfo(empId,wagesEarned[]);
showInfo(empId,wagesEarned[]);


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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<iostream>
 #include<iomanip>
 using namespace std;

 
 const int EMP = 7;
void getInfo(int empId[EMP],double wagesEarned[EMP]);
void showInfo(int empId[EMP],double wagesEarned[EMP]);

 int main()
 {
	const int EMP = 7;
	 int empId[EMP] = {565, 452, 789, 877, 845, 130, 758};
	 
	 double wagesEarned;
	
	cout <<"Welcome to the Payroll program" << endl;
	cout <<"created by " << endl << endl;
	
	
	getInfo(empId,wagesEarned[]);
	showInfo(empId,wagesEarned[]);
		
system("pause");
	return 0;
 }

 void getInfo(int empId[EMP],double wagesEarned[EMP])
 {
	 const int EMP = 7;
	 
	 double payRate;
	 double hoursWorked;
	
	 

		for(int count = 0;count <= 6; count++)
		{
			 cout << "Employee number : " << empId[count] << endl;
	
			 cout << "\nEnter employee's hour : ";
			 cin >> hoursWorked;
		while (hoursWorked < 0)
		{
			cout <<"Please enter a positive number: ";
			cin >> hoursWorked;
		}
		
			 cout << "Enter employee's pay rate: ";
			 cin >> payRate;
		while (payRate < 6.00)
		{
			cout <<"Please enter a pay rate higher than $6.00: ";
			cin >> payRate;
		}
				wagesEarned[count] = hoursWorked * payRate;
			 cout << "\n";
		 }
 }


 void showInfo(int empId[EMP],double wagesEarned[EMP])
 {
	const int EMP = 7;
	
	
	
	
	
			 for(int count = 0;count < count;count++)
				{
					
					cout << "Employee number : " << empId[count] << endl;
				cout << "Employee gross wager : " << fixed << setprecision(2) <<showpoint << wagesEarned[count] << endl;
					cout << "\n";
				}	
 }

ok ive done that now my next problem is with the functions in main


So what is the problem?
in line 21 and 22
I get this error message
error C2059: syntax error : ']'
Don't specify the brackets.

1
2
  getInfo(empId,wagesEarned);
  showInfo(empId,wagesEarned);
Topic archived. No new replies allowed.