Whoops. Thanks. It's 3am here... I'm losing it, haha.
Latest version of my code. It is calling orlando.txt and running through the numbers once, then crashing:
Code:
#include <stdio.h>
int main()
{
// Declare variables
char cityFileName[20];
int month, day, dummyMonth, dummyDay, dummyVar;
float weatherArray[12][31], tempTemp;
float tempAverage = 0.0;
// 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("orlando.txt","r");
// 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);
printf("%d - ", dummyDay);
fscanf(ifp, "%d", &dummyVar);
fscanf(ifp, "%f", &tempTemp);
printf("%d - %.2f", dummyDay, tempTemp);
if (tempTemp != -99)
{
tempAverage = (tempAverage + tempTemp)/2.0;
weatherArray [dummyMonth][dummyDay] = tempAverage;
}
fscanf(ifp, "%d", &dummyMonth);
}
// Calculate the average temperature for the month of the chosen wedding date
int monthAverageTemp = 0;
for (dummyDay=0; dummyDay < 31; dummyDay++)
{
monthAverageTemp = (monthAverageTemp + weatherArray[month][dummyDay]) / 2;
}
// Print calculations to the user
printf("The 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");
else
printf("It’s probably best to move the wedding indoors, sorry.");
return 0;
}