Oct 12, 2006 - 2:04 AM
|
|
![]() 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...
|
![]() |
Oct 12, 2006 - 6:32 AM
|
|
![]() 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] |
Oct 12, 2006 - 8:55 AM
|
|
![]() 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 |
Coomer Anyone know C++? Oct 12, 2006 - 2:04 AM
hurley97 when I put that in and ran the program I got essen... Oct 12, 2006 - 3:21 AM
phonex98 I agree with Jon. Its been a while since ive done ... Oct 12, 2006 - 8:37 AM
Starcraftjunkie x2. Initalize with the [10][5] and it should be f... Oct 12, 2006 - 12:05 PM
phonex98 im pretty sure he's using the cin (input) as a... Oct 12, 2006 - 9:38 AM
Coomer Awesome...that worked. Thanks a ton guys. Oct 12, 2006 - 12:17 PM
tomazws wow... haven't seen a C++ code for quite a whi... Oct 12, 2006 - 3:21 PM
hurley97 speaking of which... I should be writing a program... Oct 12, 2006 - 3:34 PM
Starcraftjunkie Coomer is using buckets as a variable name. He ca... Oct 12, 2006 - 8:27 PM
hurley97 ahh. the use of "int" confused me, I jus... Oct 12, 2006 - 10:49 PM
phonex98 QUOTE(hurley97 @ Oct 12, 2006 - 8:49... Oct 13, 2006 - 12:08 AM
XS4lv1Truch0x lmao i thought visual basic wass bad now im lookin... Oct 12, 2006 - 11:14 PM
Steevo < Pulls out hair <_<
I prefer Delphi... Oct 12, 2006 - 11:33 PM
XS4lv1Truch0x QUOTE(Steevo @ Oct 12, 2006 - 9:33 P... Oct 12, 2006 - 11:40 PM
hurley97 yeah I got that far (not sure if it'll work ye... Oct 13, 2006 - 12:48 AM
Starcraftjunkie err. Hurley, your program doesn't make any sen... Oct 13, 2006 - 1:11 AM
hurley97 QUOTE(Starcraftjunkie @ Oct 13, 2006 - 2... Oct 13, 2006 - 1:15 AM
Starcraftjunkie o ya.. make sure you have a line to check the inpu... Oct 13, 2006 - 1:17 AM
hurley97 QUOTE(Starcraftjunkie @ Oct 13, 2006 - 2... Oct 13, 2006 - 1:18 AM
Starcraftjunkie ez. Just use an IF loop.
you calculated your Ddo... Oct 13, 2006 - 7:56 AM
Rjb23 What is a if loop and why would you need a loop?
... Oct 13, 2006 - 8:13 AM
hurley97 31 errors
#include <iostream>
#include ... Oct 13, 2006 - 9:42 AM
tomazws CODE
#include <iostream>
#include <cma... Oct 13, 2006 - 11:40 AM
hurley97 hey thanks! that helped A LOT!
now hopef... Oct 13, 2006 - 2:00 PM
Starcraftjunkie Is the Dwf provided by the question? or do you hav... Oct 14, 2006 - 12:19 AM
hurley97 it wasn't provided but it didn't say to as... Oct 14, 2006 - 7:33 PM![]() ![]() |
| Lo-Fi Version | Time is now: January 18th, 2026 - 12:59 PM |