swapping index position of values in an element

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 826 Views - Last Post: 18 May 2013 - 09:43 AM Rate Topic: -----

#16 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10461
  • View blog
  • Posts: 38,755
  • Joined: 27-December 08

Re: swapping index position of values in an element

Posted 17 May 2013 - 05:26 PM

You've hardly done anything. Please make a good faith effort, or we're going to close your thread.

Look, I don't mean to be rude, but you're not new to the site. We shouldn't have to constantly remind you about things like where to post, using code tags, not bumping or hijacking other threads, and making some effort. You're more than welcome to shoot me a PM if you have questions regarding the rules of the site.
Was This Post Helpful? 0
  • +
  • -

#17 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1329
  • View blog
  • Posts: 4,555
  • Joined: 19-February 09

Re: swapping index position of values in an element

Posted 17 May 2013 - 06:04 PM

The size of your array is 4 rows of 8 columns.

06          int array1[4][8] =  {



This is out of bounds ...

13	 cout << array1[4][8] << endl;




... because the array goes from

 // first row first column
 cout << array1[0][0] << endl;
 // to row four, column eight (3,7)
 cout << array1[3][7] << endl;




Previously, you have iterated over the array.

07   for(int x=0; x<8; x++)
08   {
09     for(int y=0; y<4; y++)
10     {
11       array1[x][y]=0;
12     }
13   }


Was This Post Helpful? 0
  • +
  • -

#18 JJu-256  Icon User is offline

  • D.I.C Head

Reputation: -6
  • View blog
  • Posts: 115
  • Joined: 21-December 11

Re: swapping index position of values in an element

Posted 17 May 2013 - 07:54 PM

Thanks for your help. This is what I came up with so far. I don't think it works as yet as there are prevalent errors.
Maybe you can help let me know.... :bananaman:

#include <iostream>
//#include <ifstream>
#include <iomanip>
using namespace std;

int main()
{

    int i;
    i = 4;
    int j;
    j= 8;
    char array[][] = new char [4][8];
                        
    if(array[i][j]>='A' && array[i][j]<= 'Z')
    {
     array[i][j] = {
                        { A, B,  C,  D,  E,  F, G, H},
                        { I, J,  K,  L,  M,  N, O, P},
                        { Q, R,  S,  T,  U,  V, W, X},
                        { Y, Z,  A,  B,  C,  D, E, F},
                    };
    }
    else 
        if(array[i][j]>='a' && array[i][j]<= 'z')
    {
     array[i][j] =  {
                        { a, b,  c,  d,  e,  f, g, h},
                        { i, j,  k,  l,  m,  n, o, p},
                        { q, r,  s,  t,  u,  v, w, x},
                        { y, z,  a,  b,  c,  d, e, f},
                     };     
    }
 for(int i =0; i<array.length; i++)
 {
          for(int j=0; j<array[0].length; j++)
            {
 cout << array[i][j]<<endl;
 array[0][0] = 'A'; 
 array[0][1] = 'B';
 array[0][2] = 'C';
 array[0][3] = 'D';
 array[0][4] = 'E'; 
 array[0][5] = 'F';
 array[0][6] = 'G';
 array[0][7] = 'H';
 array[1][0] = 'I';
 array[1][1] = 'J';
 array[1][2] = 'K';
 array[1][3] = 'L';
 array[1][4] = 'M';
 array[1][5] = 'N';
 array[1][6] = 'O';
 array[1][7] = 'P';
 array[2][0] = 'Q';
 array[2][1] = 'R';
 array[2][2] = 'S';
 array[2][3] = 'T';
 array[2][4] = 'U';
 array[2][5] = 'V';
 array[2][6] = 'W';
 array[2][7] = 'X';
 array[3][0] = 'Y';
 array[3][1] = 'Z';
 array[3][2] = 'a';
 array[3][3] = 'b';
 array[3][4] = 'c';
 array[3][5] = 'd';
 array[3][6] = 'e';
 array[3][7] = 'f';

     }               
} 
 
          int array1[4][8] =  {
                              { 0, 27,  2, 23,  6, 29, 12,21},
                              { 3, 16,  5, 28, 11, 22, 7, 30},
                              {26, 21, 18, 15, 24,  9, 20,13},
                              {17, 4,  25, 10, 19, 14, 31, 8},
                              };
 for(int x =0; x<=3; x++)
  {
         for(int y=0; y<=7; y++)
     {
         cout << array1[x][y]<< endl;
        
     }
  }
   system("pause");
   return 0;  
    
}                         


Was This Post Helpful? 0
  • +
  • -

#19 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10461
  • View blog
  • Posts: 38,755
  • Joined: 27-December 08

Re: swapping index position of values in an element

Posted 17 May 2013 - 08:35 PM

Seriously- you have over 100 posts. We shouldn't have to twist your arm to get descriptive information! Post your exact errors.

As for your problem, why are you assigning a 2D array to an element in your 2D array?
Was This Post Helpful? 0
  • +
  • -

#20 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,385
  • Joined: 25-December 09

Re: swapping index position of values in an element

Posted 17 May 2013 - 09:26 PM

Please explain this snippet:
         for(int j=0; j<array[0].length; j++)
            {
 cout << array[i][j]<<endl;
 array[0][0] = 'A'; 
 array[0][1] = 'B';
 array[0][2] = 'C';
 array[0][3] = 'D';
 array[0][4] = 'E'; 
 array[0][5] = 'F';
 array[0][6] = 'G';
 array[0][7] = 'H';
 array[1][0] = 'I';
 array[1][1] = 'J';
 array[1][2] = 'K';
 array[1][3] = 'L';
 array[1][4] = 'M';
 array[1][5] = 'N';
 array[1][6] = 'O';
 array[1][7] = 'P';
 array[2][0] = 'Q';
 array[2][1] = 'R';
 array[2][2] = 'S';
 array[2][3] = 'T';
 array[2][4] = 'U';
 array[2][5] = 'V';
 array[2][6] = 'W';
 array[2][7] = 'X';
 array[3][0] = 'Y';
 array[3][1] = 'Z';
 array[3][2] = 'a';
 array[3][3] = 'b';
 array[3][4] = 'c';
 array[3][5] = 'd';
 array[3][6] = 'e';
 array[3][7] = 'f';

     }            


Why is this in a loop? Why are you trying to print the array contents before you initialize the array, the first time thru your loop?

Have you ever heard of the ASCII Table? Maybe you might want to look into this instead of all that initialization nonsense.

Jim
Was This Post Helpful? 0
  • +
  • -

#21 JJu-256  Icon User is offline

  • D.I.C Head

Reputation: -6
  • View blog
  • Posts: 115
  • Joined: 21-December 11

Re: swapping index position of values in an element

Posted 17 May 2013 - 10:38 PM

View Postmacosxnerd101, on 17 May 2013 - 08:35 PM, said:

Seriously- you have over 100 posts. We shouldn't have to twist your arm to get descriptive information! Post your exact errors.

As for your problem, why are you assigning a 2D array to an element in your 2D array?

Thanks a lot.

View Postjimblumberg, on 17 May 2013 - 09:26 PM, said:

Please explain this snippet:
         for(int j=0; j<array[0].length; j++)
            {
 cout << array[i][j]<<endl;
 array[0][0] = 'A'; 
 array[0][1] = 'B';
 array[0][2] = 'C';
 array[0][3] = 'D';
 array[0][4] = 'E'; 
 array[0][5] = 'F';
 array[0][6] = 'G';
 array[0][7] = 'H';
 array[1][0] = 'I';
 array[1][1] = 'J';
 array[1][2] = 'K';
 array[1][3] = 'L';
 array[1][4] = 'M';
 array[1][5] = 'N';
 array[1][6] = 'O';
 array[1][7] = 'P';
 array[2][0] = 'Q';
 array[2][1] = 'R';
 array[2][2] = 'S';
 array[2][3] = 'T';
 array[2][4] = 'U';
 array[2][5] = 'V';
 array[2][6] = 'W';
 array[2][7] = 'X';
 array[3][0] = 'Y';
 array[3][1] = 'Z';
 array[3][2] = 'a';
 array[3][3] = 'b';
 array[3][4] = 'c';
 array[3][5] = 'd';
 array[3][6] = 'e';
 array[3][7] = 'f';

     }            


Why is this in a loop? Why are you trying to print the array contents before you initialize the array, the first time thru your loop?

Have you ever heard of the ASCII Table? Maybe you might want to look into this instead of all that initialization nonsense.

Jim


The snippet is not what I wanted. I will like to know more about the ASCII you mentioned.
Was This Post Helpful? 0
  • +
  • -

#22 jimblumberg  Icon User is online

  • member icon


Reputation: 4013
  • View blog
  • Posts: 12,385
  • Joined: 25-December 09

Re: swapping index position of values in an element

Posted 18 May 2013 - 05:25 AM

Quote

The snippet is not what I wanted. I will like to know more about the ASCII you mentioned.


Have you ever heard of search engines like Google, Bing, Yahoo. They were invented to make locating information easier. I suggest you give one of them a try, you might be surprised about the amount of information available. One of the requirements of becoming a competent programmer is the ability to be able to research project requirements to determine the best algorithm to solve a particular problem.

Jim
Was This Post Helpful? 4
  • +
  • -

#23 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6057
  • View blog
  • Posts: 23,494
  • Joined: 23-August 08

Re: swapping index position of values in an element

Posted 18 May 2013 - 09:43 AM

And with that sage advice, I'm closing this help vampire topic.
Was This Post Helpful? 2
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2