![]() |
| | #1 |
| Registered User Join Date: Mar 2002
Posts: 11
| problem with 2d array program. Prgm Eng. Math Average 0,0 0,1 0,2 0,3 1,0 1,1 1,2, 1,3 and so on for five rows. The next part of the program that I'm having trouble with is finding the highest of the three marks and adding this data to the array. My messed up code for the function looks like this: } void print_marks(double marks[ROWS][COLS],double avg[ROWS],int r,int c) { int i,j; for (i=0;i<r;i=i+1) { printf("%4s%8s%8s%8s%11s\n"," ", "Prgm", "Math", "Engl", "Avrg"$ for (j=0;j<c;j=j+1) { printf("%8.1f", marks[i][j]); } printf("%11.1f\n", avg[i]); } } This part returns the expected results. The messedup find_high function: } void find_high(double marks[ROWS][COLS],int r,int c) { int i,j; for (j=0;j<r;j=j+1) { for (i=0;i<r;i=i+1) { if (marks[i][j]>marks[i+1][j]) { } I'm confused about the code for this part. Any help would be appreciated. Colin Last edited by Niloc1; 04-08-2002 at 04:48 PM. |
| Niloc1 is offline | |
| | #2 |
| Registered User Join Date: Mar 2002
Posts: 95
| your using the value R in both for loops, I'm suspecting thats your prob: Code: void find_high(double marks[ROWS][COLS],int r,int c)
{
int i,j,highest=0;
for (j=0;j<r;j++)
for (i=0;i<c;i++)
if (marks[j][i]>highest)
highest=marks[j][i];
}
you would also have a problem because I think you were reading the wrong way or atleast top to bottom rather than accross ways (rows rather than columns) and you if you had a full list then in your if statement your trying to compare it with a value that isnt defined by doing the +1. This function will give you the highest number in the entire list, if you wanted for each one then remove the first for statement. |
| Bull is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 8 Queens, problem with searching 2D array | Sentral | C++ Programming | 35 | 03-11-2009 04:12 PM |
| Help with mallocing a 2d array please? | Gatt9 | C Programming | 5 | 10-10-2008 03:45 AM |
| Unknown Memory Leak in Init() Function | CodeHacker | Windows Programming | 3 | 07-09-2004 09:54 AM |
| fopen(); | GanglyLamb | C Programming | 8 | 11-03-2002 12:39 PM |
| Simple 2D array problem...In a Hurry! | 67stangman | C++ Programming | 8 | 04-18-2002 01:22 PM |