![]() |
![]() |
![]() |
|
![]() Administrator ![]() ![]() ![]() ![]() ![]() Joined Aug 23, '02 From Seattle, WA Currently Offline Reputation: 14 (100%) ![]() |
I've been writing a program for class and was getting strange errors,
so I went through everything and eventually simplified it down to this super-simple program: CODE #include <iostream> using std::cout; using std::cin; int main() { int buckets[9][4] = {0}; for (int j = 0; j <= 9; j++) { for (int k = 0; k <= 4; k++) { cout << buckets[j][k] << " "; } cout << "\n"; } char ch; cin >> ch; } Sounds simple, right? Create a 10 row, 5 column 2-dimensional array filled with zeroes, right? The problem is that my output is this: Anyone have any idea as to what could be going on? If I manually fill the array with zeroes using two for loops, I get the correct output, but when the program tries to exit after I enter a character, I get this error: Any of you programmers out there have any ideas?
Attached image(s)
![]() ![]() -------------------- New Toyota project coming soon...
|
![]() |
![]() |
|
![]() Enthusiast ![]() ![]() Joined Dec 6, '05 From South Carolina Currently Offline Reputation: 0 (0%) ![]() |
I asked a net friend of mine and this is what he said
QUOTE Friend: well I'm not too sure, and for some reason my compiler isn't working .-_- but it looks like his array is screwed up he buts buckets[9][4] wanting an array that's 10x5 array but you have to be literal when you make an array he need to create the array with the actual size, bucket[10][5] then use it like he trying to within the code, bucket[0-9][0-4] |
![]() |
|
![]() Enthusiast ![]() ![]() ![]() ![]() ![]() Joined Feb 8, '04 From KY Currently Offline Reputation: 0 (0%) ![]() |
QUOTE(JonCars17 @ Oct 12, 2006 - 11:32 AM) [snapback]490649[/snapback] I asked a net friend of mine and this is what he said QUOTE Friend: well I'm not too sure, and for some reason my compiler isn't working .-_- but it looks like his array is screwed up he buts buckets[9][4] wanting an array that's 10x5 array but you have to be literal when you make an array he need to create the array with the actual size, bucket[10][5] then use it like he trying to within the code, bucket[0-9][0-4] This is correct. You can see by the random numbers its pulling out of the array but if that doesn't work run your code in debug and step through and look at the variables especially the array and see what it looks like(check and make sure it is really 10 x 5). CODE #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { int buckets[10][5] = {0}; for (int j = 0; j < 10; j++) { for (int k = 0; k < 5; k++) { Console::Write(buckets[j][k] + " "); } Console::Write("\n"); } return 0; } What are you doing with the cin, and ch variable? Coomer if you need more help pm me I'm a developer I mostly do javascript, sql, vb and asp.net. But C++ was the first language I learned I may be rusty but I can help. This post has been edited by Rjb23: Oct 12, 2006 - 9:09 AM |
![]() ![]() |
Lo-Fi Version | Time is now: August 3rd, 2025 - 10:17 AM |