What is wrong with my declarations?

The only errors I am getting are from the declaration of my arrays. I don't fully understand arrays, so I'm sure it's probably something simple. Any help will be greatly appreciated!

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
#include <iostream>
using namespace std; 


void title ()
{
// Output program name
cout << endl;
cout<< "                                 Assignment 6                  " <<endl;
}


int main()
{
// Declarations

const double empID[0]=56588;
const double  empID[1]=45201;
const double  empID[2]=78951;
const double  empID[3]=87775;
const double empID[4]=84512;
const double  empID[5]=13028;
const double  empID[6]=75804;

const int size=6;
int hours[size];
double payRate[size];
double wages[size];
int x,i;

title();
cout <<endl<<endl;


for (i=0; i<size;i++)
{
cout << "Please enter hours worked for employee: "<< empID[i]<<endl;
cin >> hours[i];
cout << "Please enter pay rate for employee: "<<enpID[i]<<endl;
cin >> payRate[i];
wages[i]= hours[i]* payRate[i];

if (hours[i]<0 || payRate[i]<6)
	{
	cout <<"Error: Please enter hours greater than 0 or pay rate greater than $6.00."<<endl;
	}
}

for (i=0; i<size; i++)
cout << "Employee number "<<enpID[i]<<" wages are $" <<wages[i]<<endl;

return 0;
}
You can't declare an array like that. I think you would have to do something like:

const double empID[] = { 56588, 45201, /* ... */, 75804};

EDIT: Also note that the empID array will have seven elements in it, but you are only looping until size, so you'll only check the first six.
Last edited on
Zhuge is right.

Moreover I see another problem on line 43 (if statement). In your case the only result of invalid input would be writing the error message on standard output. Your program doesn't handle how to change these values (hours, payRate) if they don't conform your requirements so despite the error message the original (wrong) values are stored.
Topic archived. No new replies allowed.