This is my code at its current state. The average for the day and the average for the month keep calculating to be the same, which makes no sense. Formula wise they should be different.
Code:
#include <stdio.h>
int main()
{
// Declare variables
char cityFileName[20];
int month, day, dummyMonth, dummyDay, dummyVar;
float weatherArray[12][31], tempTemp, tempAverage;
// Prompt user with questions
printf ("What is the month and day of your wedding?\n");
scanf("%d %d", &month, &day);
// Adjusting month and day values to align with array
month = month - 1;
day = day - 1;
printf("What file stores your city's temperature data?\n");
scanf("%s", cityFileName);
// Program will open the filename the user inputted
FILE *ifp = fopen(cityFileName,"r");
if (! ifp)
{
printf("The file did not open\n");
exit (255);
}
// Initialize the weather array to recieve temperature averages
for (dummyMonth=0; dummyMonth < 12; dummyMonth++)
{
for (dummyDay=0; dummyDay < 31; dummyDay++)
weatherArray[dummyMonth][dummyDay] = 0;
}
// Read temperature file and store temperature averages to array
fscanf(ifp, "%d", &dummyMonth);
while (dummyMonth != -1)
{
fscanf(ifp, "%d", &dummyDay);
fscanf(ifp, "%d", &dummyVar);
fscanf(ifp, "%f", &tempTemp);
if (weatherArray[dummyMonth-1][dummyDay-1] == 0)
weatherArray[dummyMonth-1][dummyDay-1] = tempTemp;
if (tempTemp != -99)
{
tempAverage = (weatherArray [dummyMonth-1][dummyDay-1] + tempTemp) / 2;
weatherArray [dummyMonth-1][dummyDay-1] = tempAverage;
//printf("%d - %d - %d - %.2f\n", dummyMonth, dummyDay, dummyVar, weatherArray [dummyMonth-1][dummyDay-1]);
}
fscanf(ifp, "%d", &dummyMonth);
}
// Calculate the average temperature for the month of the chosen wedding date
int monthAverageTemp = weatherArray[month][0];
for (dummyDay=0; dummyDay < 31; dummyDay++)
{
if (weatherArray[month][dummyDay] != 0)
{
monthAverageTemp = (monthAverageTemp + weatherArray[month][dummyDay]) / 2;
printf("\n%.2f\n", weatherArray[month][dummyDay]);
}
}
// Print calculations to the user
printf("\nThe average temperature on your wedding day is %.2f degrees F.\n",
weatherArray[month][day]);
printf("The average temperature on your wedding month is %.2f degrees F.\n",
monthAverageTemp);
// Condition that states whether wedding should be held outside or not
if ((weatherArray[month][day] >= 60) && (weatherArray [month][day] <= 75))
printf("The weather looks good for an outdoor wedding.\n");
else
printf("It is probably best to move the wedding indoors, sorry.\n");
return 0;
}