thanks again for your time dave, but im afraid im still not getting it - its really frustrating me, i just cant seem to grasp the concept of the arrays
here is the code i have got - the rest of the program seems to work fine but i cant display the wet/dry months correctly - it just keeps coming up with london and listing all the months as wet and dry..
#include <stdio.h>
#include <string.h>
const int maxrows=12;
const int maxcols=12;
const int maxchar=10;
static char place[maxrows][maxchar];
static char dummy[maxchar];
const char *months[12] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
float rain[maxrows][maxcols];
float average, annual, wet, dry, total, lowval, highval, highindex, lowindex;
FILE *fp;
main ()
{
int i=0;
if ((fp = fopen("data.txt", "r"))==NULL)
printf("Error opening file\n");
else
{
do
{
printf("\n\n");
fscanf(fp,"%s",&dummy);
if (strcmp(dummy, "ZZZZZ") !=0)
{
strcpy(place[i],dummy);
printf("%10s", place[i]);
annual=0;
for (int j=0; j<maxrows; j++)
{
fscanf(fp,"%f",&rain[i][j]);
printf("\t%2.2f",rain[i][j]);
annual=annual+rain[i][j];
}
printf("\tAnnual rainfall is %3.2f", annual);
i++;
}
} while ((strcmp(dummy,"ZZZZZ") !=0) && (i<maxrows));
// make a temp varable
int tmp = i;
printf("\n\nMonthly Average ");
//for col 0 to last coll
for (int j=0; j<tmp; j++)
{
annual=0;
average=0;
for (int i=0; i<maxrows; i++)
{
annual=annual+rain[i][j];
}
average=annual/tmp;
printf("%2.2f\t", average);
}printf("\n\n");
}
for (int i=0; i < maxcols; i++)
{
lowval = 99999;
highval = 0;
if (strcmp("ZZZZZ", place[i])!=0)
{
for (int j=0; j<maxrows; j++)
{
if (rain[i][j] > highval)
{
highval=rain[i][j];
highindex = j;
}
if (rain[i][j] < lowval)
{
lowval = rain[i][j];
lowindex = j;
}
printf("%10s\n", place[i]);
printf("\tDry Month : %s\t\tDry :%.2f\n",months[i],lowval);
printf("\tWet Month : %s\t\tWet :%.2f\n",months[j],highval);
}
}
fclose(fp);
getchar();
}
}