![]() |
| | #1 |
| Registered User Join Date: Feb 2009
Posts: 2
| this is just the part of code that doesn't work, and I'm using Dev C++ to compile it. The problem occurs when it asks you to enter the value of 'position[2][3][2][1]' (on the screen in says "enter box 2,1 postion 2,3"), when you enter the value it somehow gets stored in the variable 'b' ('b' is the first variable displayed on each cout line, ie. it asks you to "enter box b,a position d,c" each line essentially). I have attached the .cpp file if it helps, please just run the program (it's safe, u can see the code and compile it yourself) and when it asks you to "enter box 2,1 position 2,3" put in something like 5 (or a bigger number) and you'll see the problem on the next line straight away. In the code you can see this shouldn't happen. The code is as follows: Code: #include <iostream>
using namespace std;
int main(){
int x, y, z, w, vars, known, a, b, c, d;
int position[3][3][3][3];
int posible[9];
for ( a=1; a <= 3; a++ ){
for ( b=1; b <= 3; b++ ){
for ( c=1; c <= 3; c++ ){
for ( d=1; d <= 3; d++ ){
cout<<"enter box "<< b <<","<< a <<" position "<< d <<","<< c <<"\n";
cin>> position[d][c][b][a];
}
}
}
}
// display start
for ( w=1; w <= 3; w++ ){
for ( y=1; y <= y; x++ ){
for ( z=1; z <= 3; z++ ){
for ( x=1; x <= 3; x++ ){
cout<< position[x][y][z][w] <<" ";
}
cout<<" ";
}
cout<<"\n";
}
cout<<"\n";
}
cin.get();
cin.ignore();
// display end
}
*EDIT: the problem occurs in the code before where it displays (//display start), but occurs again in the displaying proccess. That is why I included it all, though you could compile only the code up to where it says "//display start" and still see the problem. Last edited by DarkFire; 02-11-2009 at 08:54 AM. Reason: added info |
| DarkFire is offline | |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Code: for ( x=1; x <= 3; x++ ){
cout<< position[x][y][z][w] <<" ";
The same applies to the input section. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #3 |
| Registered User Join Date: Feb 2009
Posts: 2
| oh, of course, silly me. I suppose the quick fix would be to make it an array of [4][4][4][4], though i should alter the code completely as to not waste memory. Thanks heaps. Also I did see the problem in the display's for y line. I just hadn't finished changing something when i copied the code. Last edited by DarkFire; 02-11-2009 at 09:09 AM. |
| DarkFire is offline | |
![]() |
| Tags |
| c++ help, error, problem |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A question related to strcmp | meili100 | C++ Programming | 6 | 07-07-2007 02:51 PM |
| WS_POPUP, continuation of old problem | blurrymadness | Windows Programming | 1 | 04-20-2007 06:54 PM |
| Unknown problem | Mindphuck | C Programming | 3 | 04-08-2006 02:35 PM |
| Laptop Problem | Boomba | Tech Board | 1 | 03-07-2006 06:24 PM |
| Unknown problem | pink_langouste | Windows Programming | 2 | 12-04-2002 12:36 AM |