And use a std::vector to hold each item's tuple. A vector can hold a dynamic number of elements, you wouldn't be restricted to 3, or having to over-allocate an array to fit a changeable number of items.
It is helpful if you include the whole code that can compile and run.
With what you have posted there is a problem:
5 6 7
voiddisplayArray(string x[][3], int r, int c);
voiddisplayPurchases(string item1, int quantity1, int price1, string item2, int quantity2, int price2, string item3, int quantity3, int price3, string item4, int quantity4, int price4)
Inside the () the parameters of each must match.
Using a struct as lastchance has suggested is the best to work with data of different types. If you can use a vector that would be the best, but a simple array would work. And you would only need a 1D array for this.
Hope that helps,
Andy
Edit: I discovered this difference when working with the program.
it depends on what exactly you want.
you can store integers as text, if you just want to print it, but not do math to it:
"3" is the string for 3, as per your example.
you can put 2 types into a container of some sort and make an array of that, as mentioned above.
From there it begins to get exotic and weird and 'maybe don't do this' areas...
the union type lets you pick what type something is from your defined set of types. But it can only hold ONE of the types, not all at once. There is a variant or something similar as well. These are uncommon, but useful at times.
you can directly hijack the bytes. This is usually not recommended.
string imanint = "12345678";// 8 bytes worth of data can hold up to 64 bit int
int * ip = (int*)(&imanint[0]);
ip[0] = 31415;
cout << ip[0];
//the string contains gibberish. Its just storing the int for whatever insane reason
cout << imanint; //binary junk
#pragma once
#include <iostream>
usingnamespace std;
struct Directory
{
string item;
int quantity;
int price;
};
However, there's an error saying "no operater '<<' matches the operands.
Also, I'm not sure if I'm using the struct properly to display it in an array, sorry.
you can't do that, you need
cout << Purchases[rows].item << " " << Purchases[rows].quantity //etc
you can overload << to work but its a little advanced. I rarely do that, as it assumes the desired format, rather than let the user of the class decide, but there are merits to both ways.