Help with array

Declare a multi-dimensional integer array with 10 rows and 20 columns with initial values of each element in the array being 0. Use a while looping statement to allow a user to enter scores into the entries of the array (make sure to check if user enters valid indices). Upon the completion of the data entry, allow user to calculate and print the sum of all the scores in any row or any column. Display the value of each element in the array with rows and columns.
Why do you want a while loop to be used? If you know the the number of entries that there are going to be, it is much easier to use a for loop.
Last edited on
my teacher wants it, in the while loop method, can you help please
This should work, I didn't feel like testing it completely.
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
using namespace std;
int main()
{
    int data [10] [20];
    int x = 0, y = 0;
    while(x<10 && y<20)
        {
            cout << "Please input the data for row " << x+1 << " and column " << y+1 << ".\n";
            cin >> data [x] [y];
            ++y;
            if (y%20==0)
            {
                ++x;
                y = 0;
            }
        }
    int addData [10];
    for (int a = 0; a<9; ++a)
    {
        for (int b = 0; b<20; ++b)
        {
            addData[a] += data[a] [b];
            cout << data [a] [b] << " ";
        }
        cout << "Row " << a+1 << " sum is " << addData[a] << endl;
    }
    return 0;
}


Another thing, don't start to rely on other people to do your assignments, if you want to pass the class, you have to do the work.
Thank you, it's just too hard I'm trying to learn it but our teacher not explaining enough to us
Topic archived. No new replies allowed.