![]() |
|
#1
|
|||
|
|||
5x5 Array Help?hey everyone i need to write a program using a 5 by 5 array. and im definately confused.
heres what i need to do Write a program that reads in a 5x5 array, prints out the sum of the rows and the sum of the columns of the array. heres what i got so far. but i dont kno if im on the right track or not? CPP / C++ / C Code:
Thanks everyone x--Jay--x Last edited by LuciWiz : 11-Jan-2007 at 09:29.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#2
|
||||
|
||||
Re: 5x5 Array Help?Quote:
CPP / C++ / C Code:
__________________
Age is unimportant -- except in cheese |
|
#3
|
|||
|
|||
Re: 5x5 Array Help?Quote:
You're fairly close. You probably don't want to pre-increment your loop conditional variables. You probably want to post-increment them. I don't know why WaltP says that "main is an INT function." Main returns an int, but main is not an "int function," since we do not describe a function by its return type. For example, if a function returned a pointer to a dynamically allocated user-defined structure of say a Box, we wouldn't call that function a "struct Box pointer function" any more than we (professional programmers) call main an "int function." However, what WaltP means by what he says is valid, please ensure that your main returns an int. Since you are returning 0 in your code, you may as well declare main to return it... I think that the following changes may be what you're looking to achieve in your code: CPP / C++ / C Code:
Output: Code:
I suppose that you have/had some intended use for the "counter" variable, but I removed it since it was unused in your code. I recommend that you research your compiler/tools so that you learn how to enable the highest degree of warnings so that it warns you of everything possible so that you are able to fix little problems as early-on as possible. :davis: |
|
#4
|
|||
|
|||
Re: 5x5 Array Help?thanks so much you guys. it was a big help. now im just working on getting it to print out the rows. so i put this line in. and it workes part of the time but it doesnt others?
rows = num[i][j] + num[i][j] + num[i][j] + num[i][j] + num[i][j]; |
|
#5
|
|||
|
|||
Re: 5x5 Array Help?Quote:
...at least try to put your code in the appropriate [c]...[/c] tags! Your above code is simply adding the same number to "rows" 5 times. I don't think that is what you want to do... CPP / C++ / C Code:
Output: Code:
If you have difficulty visualizing what is happening, use graph paper or just draw a matrix representative of what it is that you expect to see. Alternatively, use a spreadsheet program to make your 5x5 matrix. Lable the headings appropriately so that you have zero-based indexes for rows and columns such that your coordinates match the "cell" for the value you expect to be located in the cell by your code. Then, as you establish your looping requirements, you can see that in order to gain access to the row data that you must sum the values for a given row without changing the row index but by changing the column index through the extent of your matrix. When calculating the columnar values, you will need to need to loop through each row without changing the index for the column, just the row through the extent of the matrix. :davis: |
Recent GIDBlog
Developing GUIs with wxPython (Part 3) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 1-D array | jack999 | C Programming Language | 16 | 16-May-2006 12:38 |
| Need help deleting the last element in the array | headphone69 | C++ Forum | 2 | 15-Mar-2006 19:31 |
| Pointer Usage in C++: Beginner to Advanced | varunhome | C++ Forum | 0 | 19-Aug-2005 09:25 |
| Help with an array using pointers | glulu76 | C++ Forum | 1 | 01-May-2005 11:21 |
| template comiling problems - need expert debugger! | crq | C++ Forum | 1 | 01-Feb-2005 21:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The