Multidimensional/ 1-D array Probelm

Hi,

I need to have my program store names and department title stored in a two dimensonal array. I have it set up as a char type array using strings but it isn;t compling. I am just simply getting an initialzier string error. using bloodshed dev-c++ comlier. Any ideas?

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


#include <iostream>
#include <conio.h>
#include  <iomanip>

using std::cout;
using std::endl;
using std::setw;
using std::setprecision;
using std::fixed;

int main()
{

	char nameTitle [10] [9] = { {"Ollie Regan" , "William Sherman", "Maureen Mooney", "Marty Shark", "Marcella Riley"} , { "manager", "assistant manager", "produce manager", "bakery manager", "cashier manager"} };
	double string2 [5] = { 18.00, 16.00, 15.00, 15.25, 13.00};

	for ( int i = 0; i< 5; i++)
	{
		for (int j = 0; j <5; j++)
		cout << nameTitle [ i] [j];

return 0;

}
Last edited on
Yea....
char nameTitle [10] [9]

This means you're creating an array of chars of size 9, and you want 10 of these size 9 arrays.

Meaning, for 1 string you can have at most 9 letters. I'm not counting but I'm sure "William Sherman" is more than 9 letters.

ie:
char test2[2][5] = {
"cats", "dogs" };

Last edited on
thanks for the help man.. i got that part sorted out. but I still have a problem though. I have to have the name and department stored in a 2-d array and the payrate stored in a 1-d array. But the progem has to print the name and department of everyone that makes more than 15 dollars an hour. I am not sure how to do this since they are two different arrays. here is my code thus far, it won't compile because of the illegal operations of seting the arrays equal to each other, but i am not sure how to get them, where i can use the 1-d array payrates to print the name and department of the 2-d array if there pay is mor ethan 15 dollars.
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 <conio.h>
#include  <iomanip>

using std::cout;
using std::endl;
using std::setw;
using std::setprecision;
using std::fixed;

int main()
{

	static const char *nameTitle [5] [5] = {{"Ollie Regan ", 
                               "William Sherman ", 
                               "Maureen Mooney ", 
                               "Marty Shark ", 
                               "Marcella Riley "}, 
                               {"manager", 
                               " assistant manager", 
                               " produce manager", 
                               " bakery manager", 
                               " cashier manager"}};

	float payRate[5] = { 18.00, 16.00, 15.00, 15.25, 13.00};

	nameTitle[0] [0] = payRate [0];
	nameTitle[1] [1] = payRate [1];
	nameTitle[2] [2] = payRate [2];
	nameTitle[3] [3] = payRate [3];
	nameTitle[4] [4] = payRate [4];
	


	for (int nRow = 0; nRow < 5; nRow++)  
    	{ 
      		for (int nCol = 0; nCol < 5; nCol++)
      		{
        	 for (int i = 0; i < 5; i++)
		{
			if ( payrate[i] > 15.00)

			
		cout << setw (15) << nameTitle[nRow] [nCol];
     		}
     	}
    
	
	char pause = getchar();  // program pauses before ending

	getchar();

return 0;

} 
Last edited on
Topic archived. No new replies allowed.