While loop IDK what is wrong

I am still not done with this program but am having trouble with the while loop. Trying to ask the user for valid input if it is more or less then the given 2d arrray. then is to ask the user for that input to track where it is I don't know if iuse a pointer or just track it from the loop again. for example:

arr[2][3] = { 4,5,6
2,4,7}

[1][2] = 4 // when user inters 1 and 2



Thanks for the help in advanced.

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

#include <iostream>

using namespace std;

int main()
{ // reads row and column
    int row, col, mark =1; // mark is used for first sec and third
    int pickrow, pickcol; // pick row and column from the list
    int arr[5][4] = { 20,44,87,94,
                       77,36,74,68,
                       11,12,78,91,
                       41,23,76,87,
                       91,22,53,49 };

    cout << "from reading the output of the 2D array: " << endl;
    cout << "enter on witch row and column you would like to pick from \n\n" << endl;


    for(row=0; row < 5; row++ ) // prints out the arrays for row and column
    {
        cout << "for row " << mark++ << " is ";

        for(col =0; col < 4; col++)
        {
             cout << arr[row][col] << " ";

        }
    cout << endl; // to separate for next row
    }


    cout << "Now pick from witch row and column you would like to pick from \n\n" << endl;
    cout << "Pick witch row you would like to choose from, use a space to separate row and column \n";
    cin >> pickrow;
    cin >> pickcol;

    while((pickrow > 0 && pickrow <= 5) || (pickcol > 1 && pickcol <= 4)) // here is the problem
    {
        cout << "error please choose a valid input " << endl;
        cin >> pickrow;
        cin >> pickcol;
    }

    for(row=0; row < 5; row++ ) // prints out the arrays for row and column
    {
        cout << "for row " << mark++ << " is ";

        for(col =0; col < 4; col++) // also tracking where the user enters the input and if i use a pointer or not
        {
            if(pickrow == row)
            {
                cout << "you chose " << pickrow << "and is listed on " << row << endl;
            }

            if(pickcol == col)
            {
                cout << "you chose " << pickcol << "and is listed on " << col << endl;
            }

        }
    cout << endl; // to separate for next row
    }

    return 0;
}

Last edited on
Line 38 is selecting a condition of wrong input. This can occur for one of
pickrow < 0
OR
pickrow > 4
OR
pickcol < 0
OR
pickcol > 3
... which is not what you have written.
Topic archived. No new replies allowed.