Good evening,
This program complies, but right around the program starts reading the file I get the error that weather.exe has stopped working. I am at a loss as to why the program is not working Can anyone see what I have done wrong? Thanks.
Code:#include <stdio.h>
// Declare variables to recieve user input
char cityFileName[20];
int month, day;
int main()
{
// 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");
// Initialize the weather array to recieve temperature averages
float weatherArray[12][31];
int dummyMonth, dummyDay;
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
float tempTemp;
int dummyVar;
float tempAverage = 0.0;
fscanf(ifp, "%d", dummyMonth);
printf("AFTER FSCANF\n");
while (dummyMonth!= -1)
{
fscanf(ifp, "%d", dummyDay);
fscanf(ifp, "%d", dummyVar);
fscanf(ifp, "%f", 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;
}