2D Arrays with different types

I have a problem about 2D arrays if the values are from different type
that is the question

I need to use a double & integer & string type in that 2D array
As far as I know I can change the values' type to another type..
I don't know how to do it (if it's possible), can anyone give me a hint about how to do it.
Last edited on
Brush up on your pointers. Since you don't know the size of the array, you can't make a simple 2D array using type variableName[numRows][numCols]. The compiler would have to know numRows and numCols at compile time in order to reserve the space.

Pointers tend to be the hardest thing to understand, so look over your lecture notes. Read the section in your textbook. Reread it. Try making a 1-dimensional array of pointers. Ask us specific questions after trying for an hour of your 1-dimensional array not working. Try again. Research some more. Try doing a 2-dimensional array. Ask some questions. Now start doing your homework.

If you thoroughly understand pointers now, you'll thank yourself later down the line.
I do not know if I couldn't understand you or I didn't make my question clear, I apologize for that.

In that question I need to use 1 array (dynamic 2D Array) and the inputs are from different type (string for the name, integer for the number of votes and double for the percentage)

I know how to create dynamic 2D array (which related with pointers) but I don't know how to change the type of values in that array, for example if I asked the user to input the candidates name I won't face any problem with that.

However, when it comes to the number of votes the user will input the number as a string and here I face the problem, how can I change from string to integer or double and the values remain in the same array?

For me I don't think it is possible as the array accepts values from 1 type only (That's what my lecturer said), unless I save them into another variables, but the question is just complicated specially when it comes to the calculations process and comparing the number of votes or who has the highest percentage then output his name as a winner of the election.

If I saved the values into another arrays, I guess in that case my solution will be wrong because the question didn't ask for that.
Last edited on
Topic archived. No new replies allowed.