Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

why is my output in hex?

+3 votes
asked Dec 21, 2023 by Brian (150 points)
Hi, I am a beginner and was following some lessons and came up with this code.  It is supposed to run through a 2 dimensional array.  When I run it, all the numbers come out in hex instead of decimal.  here is the code:

#include <iostream>

using namespace std;

int main (){

  int seats[2][3] = {

    {1, 2, 3},

    {4, 5, 6}

  };

  for (int i = 0; i < 2; i++)

    {

      for (int j = 0; j < 3; j++)

{

cout << seats[j] << endl;

}

    }

}

1 Answer

0 votes
answered Jan 6 by banan4ik (200 points)
Your code is trying to output an array of seats, but you are using the << operator to output the entire array, not its elements. Instead, you must use the indexes i and j to access individual array elements.

Here is the corrected code:

#include <iostream>

using namespace std;

int main (){

  int seats[2][3] = {

    {1, 2, 3},

    {4, 5, 6}

  };

  for (int i = 0; i < 2; i++)

    {

      for (int j = 0; j < 3; j++)

{

cout << seats[i][j] << endl;

}

    }

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...