| | |
What's Wrong with my Array?
Thread Solved
![]() |
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?
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
Can someone take a look at my code and enlighten me?
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <conio.h> using namespace std; int binA[16][4] = { (0,0,0,0),(0,0,0,1),(0,0,1,0),(0,0,1,1), (0,1,0,0),(0,1,0,1),(0,1,1,0),(0,1,1,1), (1,0,0,0),(1,0,0,1),(1,0,1,0),(1,0,1,1), (1,1,0,0),(1,1,0,1),(1,1,1,0),(1,1,1,1)}; int main() { cout<<"This is the bin array:"<<endl; for (int r=0; r<16; r++) { for (int v=0; v<4; v++) { int t=v%4; cout<<binA[r][v]; if (v==3) cout<<" "; } } getch(); return 0; }
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
It's because you are declaring your array like this:
When you should only be using braces:
C++ Syntax (Toggle Plain Text)
int binA[16][4] = { (0,0,0,0),(0,0,0,1),(0,0,1,0),(0,0,1,1), (0,1,0,0),(0,1,0,1),(0,1,1,0),(0,1,1,1), (1,0,0,0),(1,0,0,1),(1,0,1,0),(1,0,1,1), (1,1,0,0),(1,1,0,1),(1,1,1,0),(1,1,1,1)};
C++ Syntax (Toggle Plain Text)
int binA[16][4] = { {0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1}, {0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1}, {1,0,0,0},{1,0,0,1},{1,0,1,0},{1,0,1,1}, {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."
![]() |
Similar Threads
- Using operator[] with an ArrayList (Java)
- unserialize an array! spitting out jibberish (PHP)
- letter and word counter (C)
- retrieving ids from dynamically created controls in asp.net (ASP)
- for loop error (C)
- having trouble with arrays (C++)
- Run-time Error when printing Array Contents. (C)
- how to increase the size of an array? (C)
- question about array (C++)
- I would kill for this, just a little bit (C)
Other Threads in the C++ Forum
- Previous Thread: Permutations of an N element array
- Next Thread: int main() or void main() ??!!
| Thread Tools | Search this Thread |
addition api array base based binary bitmap c++ c/c++ char class classes code coding compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email embed encryption error erroraftercompilation excel file forms fstream function functions game getline givemetehcodez gmail graph gui homework homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix matrix3d memory multiple news node output pointer problem program programming project python random read recursion reference rpg shutdown() std::coutwstring string strings temperature template test text text-file tree url variable vector video visualization win32 windows winsock word wordfrequency wxwidgets






