mardi 10 septembre 2019

2nd "if" statement not working even when it's condition is getting satisfied

We have to form a 2D array-input how many rows need to be inputted-then input the number of columns in which data is going to be entered for each row (i.e for each row the number of numbers being entered is not fixed)-then display the array.

int j;
using namespace std;
int main() {
    int a[10][10];
    int q, w;
    cout << "How many rows to be filled(out of 10)?";
    cin >> q;
    for (int i = 0; i < q; i++) {
      cout << "How many columns to be filled?(out of 10)?";
      cin >> w;
      if (w = 10) {
        for (int j = 0; j < w; j++) {
          cout << "Enter number";
          cin >> a[i][j];
        }
      }
      if (w != 10) //THIS STATEMENT IS NOT BEING EXECUTED
      {
        for (j = 0; j < w; j++) {
          cout << "Enter number";
          cin >> a[i][j];
        }
        for (int e = w + 1; e < 10; e++) {
          a[i][e] = 0;
        }
      }
    }
/*When the value of variable "W" is not 10 (let's assume 2) then it should display "Enter number" only two times and take the number 2 times. This is not happening.*/

Aucun commentaire:

Enregistrer un commentaire