I've been playing around with this for a while and just can't seem to get it right. Any help is appreciated!

string catalog[][] = { {"item1 - 0 dollar(s) each","description1"},
{"item2 - 3 dollar(s) each","description2"},
{"item3 - 5 dollar(s) each","description3"},
{"item4 - 7 dollar(s) each","description4"},
{"item5 - 9 dollar(s) each","description5"}
};

void DisplayCatalog(){
	for(int x = 0;x <= 4;x++){
		cout << catalog[x,0] << endl;
	}
}

I'm trying to get the for loop to display item1,2,3,4 and 5 but there's an error with the array: an array may not have elements of this type

When I put numbers in the brackets after catalog ([5],[2]), the error goes away. But it displays addresses like 011A1703
could someone help me with this?

The first index needs to be specified: string catalog[5][] = {...

The first index needs to be specified: string catalog[5][] = {...

Still has a red mark under the second one
If I specify one or both, I can't print out the text. Instead I get addresses
Why's that?

catalog[x,0] is not how you specify a 2D array.

catalog[x,0] is not how you specify a 2D array.

Can you please show me how?
Thanks

because every element in the array is also a array,you haven't understand string type array essential; following is what you expected:

string catalog[][32] = { {"item1 - 0 dollar(s) each","description1"},
      {"item2 - 3 dollar(s) each","description2"},
      {"item3 - 5 dollar(s) each","description3"},
      {"item4 - 7 dollar(s) each","description4"},
      {"item5 - 9 dollar(s) each","description5"}
  };
  
  void DisplayCatalog(){
          for(int x = 0;x <= 4;x++)
         {
                cout << catalog[x][0] <<" "<< catalog[x][1]<<endl;
           }
   }
commented: Let them think about it for a while! -4

string catalog[][32] = { {"item1 - 0 dollar(s) each","description1"},
{"item2 - 3 dollar(s) each","description2"},
{"item3 - 5 dollar(s) each","description3"},
{"item4 - 7 dollar(s) each","description4"},
{"item5 - 9 dollar(s) each","description5"}
};

void DisplayCatalog(){
for(int x = 0;x <= 4;x++)
{
cout << catalog[x] <<" "<< catalog[x+1]<<endl;
}
}

commented: The thread is already answered. No need to report the solution +0
string catalog[][32] = { {"item1 - 0 dollar(s) each","description1"},
    {"item2 - 3 dollar(s) each","description2"},
    {"item3 - 5 dollar(s) each","description3"},
    {"item4 - 7 dollar(s) each","description4"},
    {"item5 - 9 dollar(s) each","description5"}
    };
     
    void DisplayCatalog(){
    for(int x = 0;x <= 4;x++)
    {
    cout << catalog[x] <<" "<< catalog[x+1]<<endl;
    }
    }

enjoy the access......:)

commented: Notice the RDIT button to the left, please. Do not double post!! -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.