Storing input into a 2D Array

I am trying to find a way to store the user entry in the second column of the 2D Array. It's my second C++ assignment ever so forgive me if it's a rookie mistake. Every time I run the program it works but it only displays "0x28Feb8" after I enter the number. I've been working on this for over a dozen hours so any help is 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
#include <iostream>

using namespace std;

int main()
{
    string topics[5]{"World Hunger", "Government Oppression", "Genocide", "Disease", "Educational Deficiencies"};


    int userentry;
    int entries[2][5] = {{1,2,3,4,5},{6,7,8,9,10}};

    cout << "Pick the highest priority issue (1-5) \n";
    cout << "1: " << topics[0] << endl;
    cout << "2: " << topics[1] << endl;
    cout << "3: " << topics[2] << endl;
    cout << "4: " << topics[3] << endl;
    cout << "5: " << topics[4] << endl;
    cout << endl;
    cin >> userentry;




    userentry == entries[6];

    cout << entries << endl;
    return 0;
Line 25 has an equality comparison that has no logical purpose. On top of it, you do dereference array with out-of-range index.

Lines 14-18 do show elements from an array. However, line 27 most certainly does not.
Ok, that would explain the error. Is there a way to save a user entry into the second column of entries or should I just throw away the code altogether? Thanks for your help by the way!
C/C++ is "row-major". Therefore, entries[2][5] is usually thought as two rows times five columns.

You/user currently enter one integer. Do you want to store it into multiple elements in an array, or to only one?

Your topics is a 1D array. You dereference single elements with one index. Dereferencing 2D array requires two indices. For example,
1
2
3
int entries[2][5] = {{1,2,3,4,5},{6,7,8,9,10}};
std::cout << entries[0][4]  << '\n';
std::cout << entries[1][1]  << '\n';

5
7
This is only about 1/10th of the program I need to make. Basically I have to store 5 user entries as each element in the second column then somehow tie the first column to the topics Array. That's what the book tells me at least.
In that case the bigger question is what do you actually try to achieve?
I'll just write the description the book gives me, might give you a better idea. Not that I want the whole assignment done for me, I definitely need to learn this stuff as my major is programming.

Pick 5 causes. Use a one dimensional string array 'topics' to store the causes. To summarize the survey responses, use a 5-row, 10 column two dimensional array 'entries', each row corresponding to an element in the 'topics' array. When the program runs it should ask the user to rate each issue. Have people respond to the survey. Then have the program display a summary of the results, including:

a) A tabular report with the five topics down the left side and the 10 ratings across the top, listing in each column the number of ratings received for each topic.
b) To the right of each row, show the average of the ratings for that issue.
c) Which issue received the highest point total? Display both the issue and the point total.
d) Which issue received the lowest point total? Display both the issue and the point total.
user to rate each issue ...
Have people respond to the survey ...
the 10 ratings ...
in each column the number of ratings ...

I'm not sure what it says, but my guess is that a user must give a value [1..10] (or [0..9], or whatever set of ten different "ratings") for each topic. One element in the 2D array would then be a count of how many times that value (column) has been chosen for that issue (row) by users.
I think I might have it figured out for now. I'll label this answered and post again if I run into more problems! Thanks for the help.
Last edited on
Topic archived. No new replies allowed.