Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Matt Cain
- COP 3223
- Dr. Laviola
- Assignment #3 part 1 */
- #include <stdlib.h>
- #include <stdio.h>
- FILE *file;
- int main(void) {
- float day_total = 0; //Entering variables
- float month_total = 0;
- int day_counter = 0;
- int month_counter = 0;
- int month_check, day_check;
- char filename[20];
- printf("What is the month and day of your wedding?\n"); //Prompting user
- scanf("%d",&month_check);
- scanf("%d",&day_check);
- printf("What file stores your city's temperature data?\n");
- scanf("%s",filename);
- file = fopen(filename, "r"); //Opening file to read
- while(1){ //Scanning the file for the below values
- int month, day, year;
- float temp;
- fscanf(file,"%d",&month);
- fscanf(file,"%d",&day);
- fscanf(file,"%d",&year);
- fscanf(file,"%f",&temp);
- if(month == -1) //Breaks out of loop if it finds a -1 (Placed at the bottom of the weather file to end)
- break;
- if(day == day_check){
- day_counter++;
- day_total += temp;
- }
- if(month == month_check){
- month_counter++;
- month_total += temp;
- }
- }
- float day_average = day_total/day_counter;
- float month_average = month_total/month_counter;
- printf("The average temperature on your wedding day is %.2f\n", day_average);
- printf("The average temperature on your wedding month is %.2f\n", month_average);
- if ((day_average>=60 && day_average<=75) && (month_average>=60 && month_average<=75)) { //[60,75] Range
- printf("The weather looks good for an outdoor wedding!\n");
- }
- else
- printf("It's probably best to move the wedding indoors, sorry!\n");
- fclose(file);
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment