Thread: Need Help!!!

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    2

    Need Help!!!

    lol ok guys im a beginner at this so please dont laugh
    im having problems with this assignment
    its involving two dimensional arrays, now ive gotten the first part of the assignment to work, which is simply printing out a table with the rainfall, and the regions(i will show a sample output)...



    Region May Jun Jul Aug Sep Oct
    -------------------------------
    Ottawa 5 11 5 25 9 5
    Toronto 8 10 7 30 5 3
    London 7 6 11 27 9 7
    60
    63
    67

    ok now for the explination, the data in the table is simply the rainfall which is a two dimensional array, the regions are also a two dimensional array,
    the problem is beneith the table the 3 values are the sums, now the problem im having is putting them in the table, heres a sample of my code
    Code:
             #include <stdio.h>
             #define MONTH 6
             #define REGION 3
             void printresult(const int rainfall[][], char Region[][]);
             int sumof(const int rainfall[][]);
             int main()
             {
              int column=0,row=0, sum=0;
               const int rainfall[REGION][MONTH]=
              {
                  {5,11,5,25,9,5},
                  {8,10,7,30,5,3},
                  {7,6,11,27,9,7},
              };
              char Region[REGION][80]={" Ottawa","Toronto"," London"};
             int ADD[REGION][1];
              printresult(rainfall,Region);
         
              sumof(rainfall);
         
         
         
         
         
         
              return 0;
          }
         
          void printresult(const int rainfall[REGION][MONTH], char Region[REGION][80])
          {
         
              int row=0, column=0;
              printf(" Region May Jun Jul Aug  Sep Oct\n");
              printf(" -------------------------------\n");
         
              for(row=0;row<REGION;row++)
              {
                  for(column=0;column<80;column++)
                      printf("%c", Region[row][column]);
                  for(column=0;column<MONTH;column++)
         
                      printf(" %d  ", rainfall[row][column]);
                       printf("\n");
         
              }
    
              }
    int sumof(const int rainfall[REGION][MONTH])
         {
         
         int sum=0,row=0, column=0;
         
              for(row=0;row<REGION;row++)
                 {
                   for(column=0;column<MONTH;column++)
         
                 sum+= rainfall[row][column];
                  printf("%d", sum);
                  printf("\n");
                  sum = 0;
                  }
          return sum;
          }
    now im pretty sure i gotta declare anotehr 2 dimensional array, and fill it with the sum, and print it out with my printresult function, but i cant figure out how to do that
    please any help would be greatly appreciated

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    First off, there is no point in declaring ADD[REGION][1] instead of ADD[REGION] as they are essentially the same.

    Second, I figure your sumof function is supposed to find the sum of one row, therefore it would probably accept a 1D array as a parameter instead of a 2D array as a parameter.

    Then, after all that, you'd just want to call sumof with each REGION, and store the result into the appropriate index of your ADD array. And bingo, you're done.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    2
    thanks so much for your help, i will try exactly what you said, again i apologise this stuff goes over my head sometimes.

Popular pages Recent additions subscribe to a feed