What's Wrong with my Array?

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2005
Posts: 21
Reputation: compshooter is an unknown quantity at this point 
Solved Threads: 0
compshooter's Avatar
compshooter compshooter is offline Offline
Newbie Poster

What's Wrong with my Array?

 
0
  #1
Nov 10th, 2006
I am just trying to print out my array of binary values from 0 to 15. The output I get is wrong, very very wrong.

Can someone take a look at my code and enlighten me?

  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4. int binA[16][4] = {
  5. (0,0,0,0),(0,0,0,1),(0,0,1,0),(0,0,1,1),
  6. (0,1,0,0),(0,1,0,1),(0,1,1,0),(0,1,1,1),
  7. (1,0,0,0),(1,0,0,1),(1,0,1,0),(1,0,1,1),
  8. (1,1,0,0),(1,1,0,1),(1,1,1,0),(1,1,1,1)};
  9. int main()
  10. {
  11. cout<<"This is the bin array:"<<endl;
  12. for (int r=0; r<16; r++)
  13. {
  14. for (int v=0; v<4; v++)
  15. {
  16. int t=v%4;
  17. cout<<binA[r][v];
  18. if (v==3)
  19. cout<<" ";
  20. }
  21. }
  22. getch();
  23. return 0;
  24. }

The result I get is...

0101 0101 0101 0101 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000

What's going on
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: What's Wrong with my Array?

 
0
  #2
Nov 10th, 2006
It's because you are declaring your array like this:
  1. int binA[16][4] = {
  2. (0,0,0,0),(0,0,0,1),(0,0,1,0),(0,0,1,1),
  3. (0,1,0,0),(0,1,0,1),(0,1,1,0),(0,1,1,1),
  4. (1,0,0,0),(1,0,0,1),(1,0,1,0),(1,0,1,1),
  5. (1,1,0,0),(1,1,0,1),(1,1,1,0),(1,1,1,1)};
When you should only be using braces:
  1. int binA[16][4] = {
  2. {0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},
  3. {0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1},
  4. {1,0,0,0},{1,0,0,1},{1,0,1,0},{1,0,1,1},
  5. {1,1,0,0},{1,1,0,1},{1,1,1,0},{1,1,1,1}};
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 21
Reputation: compshooter is an unknown quantity at this point 
Solved Threads: 0
compshooter's Avatar
compshooter compshooter is offline Offline
Newbie Poster

Re: What's Wrong with my Array?

 
0
  #3
Nov 10th, 2006
It worked! Thanks so much:!:
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC